~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/pl/tcl/modules/unknown.pltcl

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#---------------------------------------------------------------------
 
2
# Support for unknown command
 
3
#---------------------------------------------------------------------
 
4
 
 
5
proc unknown {proname args} {
 
6
    upvar #0    __PLTcl_unknown_support_plan_modname    p_mod
 
7
    upvar #0    __PLTcl_unknown_support_plan_modsrc     p_src
 
8
 
 
9
    #-----------------------------------------------------------
 
10
    # On first call prepare the plans
 
11
    #-----------------------------------------------------------
 
12
    if {![info exists p_mod]} {
 
13
        set p_mod [spi_prepare                                  \
 
14
                "select modname from pltcl_modfuncs             \
 
15
                 where funcname = \$1" name]
 
16
        set p_src [spi_prepare                                  \
 
17
                "select modseq, modsrc from pltcl_modules       \
 
18
                 where modname = \$1                            \
 
19
                 order by modseq" name]
 
20
    }
 
21
 
 
22
    #-----------------------------------------------------------
 
23
    # Lookup the requested function in pltcl_modfuncs
 
24
    #-----------------------------------------------------------
 
25
    set n [spi_execp -count 1 $p_mod [list [quote $proname]]]
 
26
    if {$n != 1} {
 
27
        #-----------------------------------------------------------
 
28
        # Not found there either - now it's really unknown
 
29
        #-----------------------------------------------------------
 
30
        return -code error "unknown command '$proname'"
 
31
    }
 
32
 
 
33
    #-----------------------------------------------------------
 
34
    # Collect the source pieces from pltcl_modules
 
35
    #-----------------------------------------------------------
 
36
    set src ""
 
37
    spi_execp $p_src [list [quote $modname]] {
 
38
        append src $modsrc
 
39
    }
 
40
 
 
41
    #-----------------------------------------------------------
 
42
    # Load the source into the interpreter
 
43
    #-----------------------------------------------------------
 
44
    if {[catch {
 
45
            uplevel #0 "$src"
 
46
        } msg]} {
 
47
        elog NOTICE "pltcl unknown: error while loading module $modname"
 
48
        elog WARN $msg
 
49
    }
 
50
 
 
51
    #-----------------------------------------------------------
 
52
    # This should never happen
 
53
    #-----------------------------------------------------------
 
54
    if {[catch {info args $proname}]} {
 
55
        return -code error \
 
56
            "unknown command '$proname' (still after loading module $modname)"
 
57
    }
 
58
 
 
59
    #-----------------------------------------------------------
 
60
    # Finally simulate the initial procedure call
 
61
    #-----------------------------------------------------------
 
62
    return [uplevel 1 $proname $args]
 
63
}
 
64
 
 
65