source: trunk/data/konvert/postnas_0.7/pg-to-oci.pl @ 209

Revision 209, 4.8 KB checked in by j.e.fischer, 8 years ago (diff)

Oracle-Fixes:

  • Trigger: Einträge in "DELETE".typename auf 30 Zeichen kürzen
  • pg-to-oci.pl: Kommentare zu PostGIS-Metatabellen überspringen

Schemaänderungen:

  • weitere Kommentare zu neuen Tabellen ergänzt
  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3#############################################################################
4#    pg-to-oci.pl - ALKIS-PostgreSQL-Schema fÃŒr Oracle vorbereiten
5#    ---------------------
6#    begin                : 2013-01-18
7#    copyright            : (C) 2013 by Juergen Fischer, norBIT GmbH
8#    email                : jef at norbit dot de
9#############################################################################
10#                                                                         
11# Permission is hereby granted, free of charge, to any person obtaining a
12# copy of this software and associated documentation files (the "Software"),
13# to deal in the Software without restriction, including without limitation
14# the rights to use, copy, modify, merge, publish, distribute, sublicense,
15# and/or sell copies of the Software, and to permit persons to whom the
16# Software is furnished to do so, subject to the following conditions:
17#
18# The above copyright notice and this permission notice shall be included
19# in all copies or substantial portions of the Software.
20#
21# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27# DEALINGS IN THE SOFTWARE.
28#                                                                         
29#############################################################################
30
31open I, "alkis_PostNAS_0.7_schema.sql";
32open O, ">alkis_PostNAS_0.7_ORACLE_schema.sql";
33
34$i = 0;
35print O "-- Automatisch mit pg-to-oci.pl konvertiert.\n---\n---\n\n";
36
37while(<I>) {
38        # Kommentare entfernen
39        s/,\s*--.*$/,/;
40        s/;\s*--.*$/;/;
41        s/\s*--.*$//;
42
43        s/^\s+SET client_encoding = 'UTF8';/set serveroutput on\nset autocommit on\nset feedback off\nset verify off\n/;
44        s/^\s+SET default_with_oids = false;/define alkis_epsg=\&1/;
45        s/\\set ON_ERROR_STOP/whenever sqlerror exit 1/;
46
47        # Funktionsinclude ÃŒberspringen
48        next if /\\i\s+alkis-functions/;
49       
50        # Includes umwandeln
51        s/\\i alkis-trigger.sql/@@ alkis-trigger-oracle.sql/;
52
53        # Datentypen abbilden
54        s/varchar\s+default\s+false/varchar2(5) default 'false'/i;
55        s/varchar\s+default\s+'false'/varchar2(5) default 'false'/i;
56        s/boolean\s+default\s+false/varchar2(5) default 'false'/i;
57        s/\bvarchar\[\]/varchar2(2047)/;
58        s/\binteger\[\]/varchar2(2047)/;
59        s/\bvarchar\b,/varchar2(2047),/;
60        s/\bdouble precision\[\]/varchar2(2047)/;
61        s/serial/integer/;
62        s/boolean/varchar2(5)/;
63
64        # Feldnamen auf OCI Defaults abbilden
65        s/wkb_geometry/ora_geometry/;
66        s/ogc_fid/ogr_fid/;
67
68        s/USING btree //;
69
70        s/SELECT alkis_drop\(\);/-- $1/;
71
72        # Indexnamen ersetzen
73        if( /CREATE( UNIQUE)? INDEX (\S+)/ ) {
74                s/INDEX \S+/INDEX ALKIS_$i/;
75                $i++;
76        }
77
78        # Constraintnamen ersetzen
79        if( /CONSTRAINT (\S+)/ ) {
80                s/CONSTRAINT \S+/CONSTRAINT ALKIS_$i/;
81                $i++;
82        }
83
84        # RÀumliche Indizes konvertieren
85        s/CREATE\s+INDEX\s+(\S+)\s+ON\s+(\S+)\s+USING\s+gist\s*\((\S+)\);/CREATE INDEX \U$1\E ON \U$2\E(\U$3\E) INDEXTYPE IS MDSYS.SPATIAL_INDEX PARALLEL;/i;
86
87        # Tabelle ggf. vor dem Anlegen droppen und aus den Metadaten löschen
88        s/CREATE TABLE (\S+)/DELETE FROM user_sdo_geom_metadata WHERE upper(table_name)='\U$1\E';\nBEGIN EXECUTE IMMEDIATE 'DROP TABLE \U$1\E CASCADE CONSTRAINTS'; EXCEPTION WHEN OTHERS THEN NULL; END;\n\/\nCREATE TABLE \U$1/;
89
90        # Anlegen der Geometriespalte anpassen und fÃŒr Metadateneintrag sorgen
91        s/SELECT AddGeometryColumn\('([^']+)','([^']+)',:alkis_epsg,'[^']+',2\);.*$/ALTER TABLE \U$1\E ADD \U$2\E MDSYS.SDO_GEOMETRY;\nINSERT INTO user_sdo_geom_metadata\(table_name,column_name,srid,diminfo\) VALUES \('\U$1\E','\U$2\E',&&alkis_epsg,mdsys.sdo_dim_array\(mdsys.sdo_dim_element\('X',200000,800000,0.001\),mdsys.sdo_dim_element\('Y',5200000,6100000,0.001\)\)\);/;
92        s/SELECT AddGeometryColumn\('([^']+)','([^']+)',:alkis_epsg,'[^']+',3\);.*$/ALTER TABLE \U$1\E ADD \U$2\E MDSYS.SDO_GEOMETRY;\nINSERT INTO user_sdo_geom_metadata\(table_name,column_name,srid,diminfo\) VALUES \('\U$1\E','\U$2\E',&&alkis_epsg,mdsys.sdo_dim_array\(mdsys.sdo_dim_element\('X',200000,800000,0.001\),mdsys.sdo_dim_element\('Y',5200000,6100000,0.001\),mdsys.sdo_dim_element\('Z',-50,3000,0.001\)\)\);/;
93
94        # DELETE-SchlÃŒsselwort quoten
95        s/"delete"/"DELETE"/;
96        s/ALTER TABLE DELETE/ALTER TABLE "DELETE"/;
97        s/'"DELETE"'/'DELETE'/g;
98        s/COMMENT ON COLUMN delete/COMMENT ON COLUMN "DELETE"/;
99
100        # Oracle kennt keine Indexkommentare
101        s/COMMENT ON INDEX .*$//;
102
103        # Überlange Bezeichner kÃŒrzen und in Großbuchstaben wandeln
104        s/([A-Z_]{30})[A-Z_]+/\U$1/gi;
105
106        next if /^COMMENT ON TABLE (geometry_columns|spatial_ref_sys)/;
107
108        next if /^\s*$/;
109
110        print O;
111}
112
113print O "purge recyclebin;\nQUIT;\n";
114close O;
115
116close I;
117
118# vim: set nowrap :
Note: See TracBrowser for help on using the repository browser.