Skip to content

Commit 2f3d659

Browse files

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed
 
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
-- A script to create a number of tables in a PostGIS enabled
2+
-- PostgreSQL database that test the ability of Qgis to load said
3+
-- tables.
4+
5+
-- $Id:$
6+
7+
-- These are all in the public schema (need to do a set for a non-public shema)
8+
9+
-- normal table
10+
-- Should load
11+
CREATE TABLE test0 (id int4 primary key) WITHOUT OIDS;
12+
SELECT addgeometrycolumn('public','test0','the_geom',4326,'LINESTRING',2);
13+
INSERT INTO test0 (id, the_geom) values (0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
14+
15+
-- no select permission on table
16+
-- Should NOT load
17+
CREATE TABLE test1 (id int4);
18+
SELECT addgeometrycolumn('public','test1','the_geom',4326,'LINESTRING',2);
19+
INSERT INTO test1 (id, the_geom) values (0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
20+
REVOKE SELECT ON test1 FROM public;
21+
22+
-- no primary key on table, but has an oid
23+
-- Should load
24+
CREATE TABLE TEST2 (id int4) WITH OIDS;
25+
SELECT addgeometrycolumn('public','test2','the_geom',4326,'LINESTRING',2);
26+
INSERT INTO test2 (id, the_geom) values (0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
27+
28+
-- primary key of non int4 type, but has an oid
29+
-- Should load
30+
CREATE TABLE test3 (id double precision PRIMARY KEY) WITH OIDS;
31+
SELECT addgeometrycolumn('public','test3','the_geom',4326,'LINESTRING',2);
32+
INSERT INTO test3 (id, the_geom) values (0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
33+
34+
-- no primary key, no oid, no other field of type int4 with unique constraint
35+
-- Should NOT load
36+
CREATE TABLE test4 (id double precision) WITHOUT OIDS;
37+
SELECT addgeometrycolumn('public','test4','the_geom',4326,'LINESTRING',2);
38+
INSERT INTO test4 (id, the_geom) values (0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
39+
40+
-- no primary key, no oid, but an int4 column with a unique constraint
41+
-- Should load
42+
CREATE TABLE test5 (id int4 UNIQUE) WITHOUT OIDS;
43+
SELECT addgeometrycolumn('public','test5','the_geom',4326,'LINESTRING',2);
44+
INSERT INTO test5 (id, the_geom) values (0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
45+
46+
-- no primary key, no oid, but an int4 column, but without a unique
47+
-- constraint, but unique data
48+
-- Should load
49+
CREATE TABLE test6 (id int4) WITHOUT OIDS;
50+
SELECT addgeometrycolumn('public','test6','the_geom',4326,'LINESTRING',2);
51+
INSERT INTO test6 (id, the_geom) values (0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
52+
INSERT INTO test6 (id, the_geom) values (1, geomfromtext('LINESTRING(151 -43, 161 -44)',4326));
53+
54+
-- no primary key, no oid, but an int4 column, but without a unique
55+
-- constraint, and duplicate data
56+
-- Should NOT load
57+
CREATE TABLE test7 (id int4) WITHOUT OIDS;
58+
SELECT addgeometrycolumn('public','test7','the_geom',4326,'LINESTRING',2);
59+
INSERT INTO test7 (id, the_geom) values (0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
60+
INSERT INTO test7 (id, the_geom) values (0, geomfromtext('LINESTRING(151 -43, 161 -44)',4326));
61+
62+
-- no primary key, no oid, but a non int4 column with a unique constraint
63+
-- Should NOT load
64+
CREATE TABLE test8 (id double precision NOT NULL UNIQUE) WITHOUT OIDS;
65+
SELECT addgeometrycolumn('public','test8','the_geom',4326,'LINESTRING',2);
66+
INSERT INTO test8 (id, the_geom) values (0.0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
67+
68+
-- a primary key that covers more than one column, and no oid
69+
-- Should NOT load
70+
CREATE TABLE test9 (id1 int4, id2 int4, PRIMARY KEY (id1, id2)) WITHOUT OIDS;
71+
SELECT addgeometrycolumn('public','test9','the_geom', 4326, 'LINESTRING',2);
72+
INSERT INTO test9 (id1, id2, the_geom) values (0, 0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
73+
74+
-- a primary key that covers more than one column, and no oid, but with a
75+
-- unique constraint on another int4 column
76+
-- Should load
77+
CREATE TABLE test10 (id1 int4, id2 int4, id3 int4 NOT NULL UNIQUE, PRIMARY KEY (id1, id2)) WITHOUT OIDS;
78+
SELECT addgeometrycolumn('public','test10','the_geom', 4326, 'LINESTRING',2);
79+
INSERT INTO test10 (id1, id2, id3, the_geom) values (0, 0, 0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
80+
81+
-- a primary key that covers more than one column, but with an oid
82+
-- Should load
83+
CREATE TABLE test11 (id1 int4, id2 int4, PRIMARY KEY (id1, id2)) WITH OIDS;
84+
SELECT addgeometrycolumn('public','test11','the_geom', 4326, 'LINESTRING',2);
85+
INSERT INTO test11 (id1, id2, the_geom) values (0, 0, geomfromtext('LINESTRING(150 -43, 160 -44)',4326));
86+
87+
-- a proper table, but with no data in it
88+
-- Should load
89+
CREATE TABLE test12 (id int4 primary key) WITHOUT OIDS;
90+
SELECT addgeometrycolumn('public', 'test12', 'the_geom', 4326, 'LINESTRING', 2);
91+
92+
-- And now the views...
93+
94+
-- Note views which refer to tables that are loaded only due to their
95+
-- having an oid column will not load because the view doesn't have
96+
-- access to the oid (unless it is explicitly included in the view).
97+
98+
99+
-- Should not load
100+
CREATE VIEW v_test1 AS SELECT * from test1;
101+
102+
-- Should load
103+
CREATE VIEW v_test2 AS SELECT *, oid from test2;
104+
105+
-- Should load
106+
CREATE VIEW v_test3 AS SELECT *, oid from test3;
107+
108+
-- Should not load
109+
CREATE VIEW v_test4 AS SELECT * from test4;
110+
111+
-- Should load
112+
CREATE VIEW v_test5 AS SELECT * from test5;
113+
114+
-- Should load
115+
CREATE VIEW v_test6 AS SELECT * from test6;
116+
117+
-- Should not load
118+
CREATE VIEW v_test7 AS SELECT * from test7;
119+
120+
-- Should not load
121+
CREATE VIEW v_test8 AS SELECT * from test8;
122+
123+
-- Should not load
124+
CREATE VIEW v_test9 AS SELECT * from test9;
125+
126+
-- Should load
127+
CREATE VIEW v_test10 AS SELECT * from test10;
128+
129+
-- Should not load
130+
CREATE VIEW v_test11 AS SELECT *, oid from test11;
131+
132+
-- Should load
133+
CREATE VIEW v_test12 AS SELECt * from test12;
134+
135+
-- and how to delete the tables
136+
SELECT dropgeometrytable('public','test0');
137+
SELECT dropgeometrytable('public','test1');
138+
SELECT dropgeometrytable('public','test2');
139+
SELECT dropgeometrytable('public','test3');
140+
SELECT dropgeometrytable('public','test4');
141+
SELECT dropgeometrytable('public','test5');
142+
SELECT dropgeometrytable('public','test6');
143+
SELECT dropgeometrytable('public','test7');
144+
SELECT dropgeometrytable('public','test8');
145+
SELECT dropgeometrytable('public','test9');
146+
SELECT dropgeometrytable('public','test10');
147+
SELECT dropgeometrytable('public','test11');
148+
SELECT dropgeometrytable('public','test12');
149+
150+
151+
DROP VIEW v_test1;
152+
DROP VIEW v_test2;
153+
DROP VIEW v_test3;
154+
DROP VIEW v_test4;
155+
DROP VIEW v_test5;
156+
DROP VIEW v_test6;
157+
DROP VIEW v_test7;
158+
DROP VIEW v_test8;
159+
DROP VIEW v_test9;
160+
DROP VIEW v_test10;
161+
DROP VIEW v_test11;
162+
DROP VIEW v_test12;

0 commit comments

Comments
 (0)
Please sign in to comment.