~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/pl/tcl/modules/pltcl_delmod.in

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
# src/pl/tcl/modules/pltcl_delmod.in
 
3
#
 
4
# Start tclsh \
 
5
exec @TCLSH@ "$0" "$@"
 
6
 
 
7
#
 
8
# Code still has to be documented
 
9
#
 
10
 
 
11
#load /usr/local/pgsql/lib/libpgtcl.so
 
12
package require Pgtcl
 
13
 
 
14
 
 
15
#
 
16
# Check for minimum arguments
 
17
#
 
18
if {$argc < 1} {
 
19
    puts stderr ""
 
20
    puts stderr "usage: pltcl_delmod dbname \[options\] modulename \[...\]"
 
21
    puts stderr ""
 
22
    puts stderr "options:"
 
23
    puts stderr "    -host hostname"
 
24
    puts stderr "    -port portnumber"
 
25
    puts stderr ""
 
26
    exit 1
 
27
}
 
28
 
 
29
#
 
30
# Remember database name and initialize options
 
31
#
 
32
set dbname [lindex $argv 0]
 
33
set options ""
 
34
set errors 0
 
35
set opt ""
 
36
set val ""
 
37
 
 
38
set i 1
 
39
while {$i < $argc} {
 
40
    if {[string compare [string index [lindex $argv $i] 0] "-"] != 0} {
 
41
        break;
 
42
    }
 
43
 
 
44
    set opt [lindex $argv $i]
 
45
    incr i
 
46
    if {$i >= $argc} {
 
47
        puts stderr "no value given for option $opt"
 
48
        incr errors
 
49
        continue
 
50
    }
 
51
    set val [lindex $argv $i]
 
52
    incr i
 
53
 
 
54
    switch -- $opt {
 
55
        -host {
 
56
            append options "-host \"$val\" "
 
57
        }
 
58
        -port {
 
59
            append options "-port $val "
 
60
        }
 
61
        default {
 
62
            puts stderr "unknown option '$opt'"
 
63
            incr errors
 
64
        }
 
65
    }
 
66
}
 
67
 
 
68
#
 
69
# Final syntax check
 
70
#
 
71
if {$i >= $argc || $errors > 0} {
 
72
    puts stderr ""
 
73
    puts stderr "usage: pltcl_delmod dbname \[options\] modulename \[...\]"
 
74
    puts stderr ""
 
75
    puts stderr "options:"
 
76
    puts stderr "    -host hostname"
 
77
    puts stderr "    -port portnumber"
 
78
    puts stderr ""
 
79
    exit 1
 
80
}
 
81
 
 
82
proc delmodule {conn modname} {
 
83
    set xname $modname
 
84
    regsub -all {\\} $xname {\\} xname
 
85
    regsub -all {'}  $xname {''} xname
 
86
 
 
87
    set found 0
 
88
    pg_select $conn "select * from pltcl_modules where modname = '$xname'" \
 
89
    MOD {
 
90
        set found 1
 
91
        break;
 
92
    }
 
93
 
 
94
    if {!$found} {
 
95
        puts "Module $modname not found in pltcl_modules"
 
96
        puts ""
 
97
        return
 
98
    }
 
99
 
 
100
    pg_result \
 
101
        [pg_exec $conn "delete from pltcl_modules where modname = '$xname'"] \
 
102
        -clear
 
103
    pg_result \
 
104
        [pg_exec $conn "delete from pltcl_modfuncs where modname = '$xname'"] \
 
105
        -clear
 
106
 
 
107
    puts "Module $modname removed"
 
108
}
 
109
 
 
110
set conn [eval pg_connect $dbname $options]
 
111
 
 
112
while {$i < $argc} {
 
113
    delmodule $conn [lindex $argv $i]
 
114
    incr i
 
115
}
 
116
 
 
117
pg_disconnect $conn