~ubuntu-branches/ubuntu/maverick/libpgjava/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-04-25 00:07:07 UTC
  • mfrom: (1.3.1 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060425000707-6lr2s0awuz4z48hm
* Drop support for the old jdbc2 driver (can be reverted if wanted)
  (closes: #358345).
* New upstream (thanks to Wolfgang Baer).

Show diffs side-by-side

added added

removed removed

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