~ubuntu-branches/ubuntu/feisty/postgis/feisty

« back to all changes in this revision

Viewing changes to create_undef.pl

  • Committer: Bazaar Package Importer
  • Author(s): Alex Bodnaru
  • Date: 2005-05-05 10:02:45 UTC
  • Revision ID: james.westby@ubuntu.com-20050505100245-3005l6jn1jwvpsrw
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# perl create_undef.pl <postgis.sql>
 
2
# creates a new sql script to delete all the postgis functions et al.
 
3
 
 
4
($#ARGV == 1) || die "Usage: perl create_undef.pl <postgis.sql> <pgsql_version #>\nCreates a new SQL script to delete all the PostGIS functions.\n";
 
5
 
 
6
# drops are in the following order:
 
7
#       1. Indexing system stuff
 
8
#       2. Meta datatables <not done>
 
9
#       3. Aggregates 
 
10
#       3. Casts
 
11
#       4. Operators 
 
12
#       5. Functions
 
13
#       6. Types
 
14
#       7. Tables
 
15
 
 
16
my @aggs = ();
 
17
my @casts = ();
 
18
my @funcs = ();
 
19
my @types = ();
 
20
my @ops = ();
 
21
 
 
22
my $version = $ARGV[1];
 
23
 
 
24
print "BEGIN;\n";
 
25
 
 
26
if ( $version ge "73" ) 
 
27
{
 
28
        print "-- Drop index bindings from system tables\n";
 
29
        print "DROP OPERATOR CLASS gist_geometry_ops USING gist CASCADE;\n";
 
30
}
 
31
else 
 
32
{
 
33
        print "-- Drop index bindings from system tables\n";
 
34
        print "DELETE FROM pg_amproc WHERE amopclaid = (SELECT oid FROM pg_opclass WHERE opcname = 'gist_geometry_ops');\n";
 
35
        print "DELETE FROM pg_amop WHERE amopclaid = (SELECT oid FROM pg_opclass WHERE opcname = 'gist_geometry_ops');\n";
 
36
        print "DELETE FROM pg_opclass WHERE opcname = 'gist_geometry_ops';\n";
 
37
}
 
38
 
 
39
 
 
40
open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n";
 
41
 
 
42
while( my $line = <INPUT>)
 
43
{
 
44
        $line =~ s/[\r\n]//g;
 
45
        push (@funcs, $line) if ($line =~ /^create function/i);
 
46
        push (@funcs, $line) if ($line =~ /^create or replace function/i);
 
47
        push (@ops, $line) if ($line =~ /^create operator.*\(/i);
 
48
        push (@aggs, $line) if ($line =~ /^create aggregate/i);
 
49
        push (@types, $line) if ($line =~ /^create type/i);
 
50
        push (@casts, $line) if ($line =~ /^create cast/i);
 
51
}
 
52
 
 
53
close( INPUT );
 
54
 
 
55
print "-- Drop all aggregates.\n";
 
56
 
 
57
foreach my $agg (@aggs)
 
58
{
 
59
        if ( $agg =~ /create aggregate\s*(\w+)\s*\(/i )
 
60
        {
 
61
                if ( $version eq "71" ) 
 
62
                {
 
63
                        print "DROP AGGREGATE $1 geometry;\n";
 
64
                }
 
65
                else 
 
66
                {
 
67
                        print "DROP AGGREGATE $1 ( geometry );\n";
 
68
                }
 
69
        }
 
70
        else
 
71
        {
 
72
                die "Couldn't parse line: $agg\n";
 
73
        }
 
74
}
 
75
 
 
76
print "-- Drop all operators.\n";
 
77
 
 
78
foreach my $op (@ops)
 
79
{
 
80
        if ($op =~ /create operator ([^(]+)/i )
 
81
        {
 
82
                if ( $version ge "73" ) 
 
83
                {
 
84
                        print "DROP OPERATOR $1 (geometry,geometry) CASCADE;\n";
 
85
                }
 
86
                else
 
87
                {
 
88
                        print "DROP OPERATOR $1 (geometry,geometry);\n";
 
89
                }
 
90
        }
 
91
        else
 
92
        {
 
93
                die "Couldn't parse line: $op\n";
 
94
        }
 
95
}
 
96
 
 
97
        
 
98
print "-- Drop all casts.\n";
 
99
 
 
100
foreach my $cast (@casts)
 
101
{
 
102
        if ($cast =~ /create cast\s*\((.+?)\)/i )
 
103
        {
 
104
                print "DROP CAST ($1);\n";
 
105
        }
 
106
        else
 
107
        {
 
108
                die "Couldn't parse line: $cast\n";
 
109
        }
 
110
}
 
111
 
 
112
print "-- Drop all functions.\n";
 
113
 
 
114
foreach my $fn (@funcs)
 
115
{
 
116
        if ($fn =~ /.* function ([^(]+)\((.*)\)/i )
 
117
        {
 
118
                my $fn_nm = $1;
 
119
                my $fn_arg = $2;
 
120
 
 
121
                if ( $version ge "73" )
 
122
                {
 
123
                        if ( ! ( $fn_nm =~ /_in/i || $fn_nm =~ /_out/i || $fn_nm =~ /_recv/i || $fn_nm =~ /_send/i || $fn_nm =~ /_analyze/i ) ) 
 
124
                        {
 
125
                                print "DROP FUNCTION $fn_nm ($fn_arg) CASCADE;\n";
 
126
                        } 
 
127
                }
 
128
                else
 
129
                {
 
130
                        print "DROP FUNCTION $fn_nm ($fn_arg);\n";
 
131
                }
 
132
        }
 
133
        else
 
134
        {
 
135
                die "Couldn't parse line: $fn\n";
 
136
        }
 
137
}
 
138
 
 
139
print "-- Drop all types.\n";
 
140
 
 
141
foreach my $type (@types)
 
142
{
 
143
        if ($type =~ /create type ([^(]+)/i )
 
144
        {
 
145
                if ( $version ge "73" ) 
 
146
                {
 
147
                        print "DROP TYPE $1 CASCADE;\n";
 
148
                }
 
149
                else 
 
150
                {
 
151
                        print "DROP TYPE $1;\n";
 
152
                }
 
153
        }
 
154
        else
 
155
        {
 
156
                die "Couldn't parse line: $type\n";
 
157
        }
 
158
}
 
159
 
 
160
print "-- Drop all tables.\n";
 
161
print "DROP TABLE spatial_ref_sys;\n";
 
162
print "DROP TABLE geometry_columns;\n";
 
163
print "\n";
 
164
 
 
165
print "COMMIT;\n";
 
166
 
 
167
1;
 
168