File: create_extension_unpackage.pl

package info (click to toggle)
postgis 3.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 70,052 kB
  • sloc: ansic: 162,204; sql: 93,950; xml: 53,121; cpp: 12,646; perl: 5,658; sh: 5,369; makefile: 3,434; python: 1,205; yacc: 447; lex: 151; pascal: 58
file content (60 lines) | stat: -rwxr-xr-x 1,408 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env perl

#
# PostGIS - Spatial Types for PostgreSQL
# http://postgis.net
#
# Copyright (C) 2017 Sandro Santilli <strk@kbt.io>
#
# This is free software; you can redistribute and/or modify it under
# the terms of the GNU General Public Licence. See the COPYING file.
#

use warnings;
use strict;
use POSIX 'strftime';

eval "exec perl -w $0 $@"
  if (0);


die "Usage: perl $0 <extname> [<sqlfile>]\n"
  . "  Prints SQL to drop objects dropped by given SQL file\n"
  . "  from extension with given name.\n"
unless @ARGV;

my $extname = shift(@ARGV);

while(<>)
{

  if ( /_postgis_drop_function_by_signature\(/ )
  {
    s/SELECT _postgis_drop_function_by_signature\('/DROP FUNCTION /;
    s/'.*/;/;
  }
  elsif ( /_postgis_drop_function_by_identity\(/ )
  {
    #print "-- FUNCTION by id: $_\n";
    s/SELECT _postgis_drop_function_by_identity\('/DROP FUNCTION /;
    s/' *, *'/(/;
    #print "-- FUNCTION by id (2): $_\n";
    s/'.*;/);/;
    #print "-- FUNCTION by id (3): $_\n";
  }

  /^DROP/i or next;
  s/ IF EXISTS//i;
  s/ CASCADE//i;
  chop;

  print 'DO $$ BEGIN ALTER EXTENSION ' . $extname
    . ' ' . $_ . 'EXCEPTION '
    . 'WHEN object_not_in_prerequisite_state OR undefined_function OR undefined_object THEN '
    . " RAISE NOTICE '%', SQLERRM; "
    . 'WHEN OTHERS THEN '
    . " RAISE EXCEPTION 'Got % - %', SQLSTATE, SQLERRM; "
    . 'END $$ LANGUAGE ' . "'plpgsql';\n";
}

1;