svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.sqlite / org.gvsig.sqlite.provider / src / test / resources / org / gvsig / sqlite / dal / createTable.sql @ 47788
History | View | Annotate | Download (4.93 KB)
1 |
-- normalize-spaces false
|
---|---|
2 |
-- strip-start false
|
3 |
-- remove-nl false
|
4 |
|
5 |
-- begin createTable
|
6 |
CREATE TABLE IF NOT EXISTS gpkg_contents (table_name TEXT NOT NULL PRIMARY KEY,data_type TEXT NOT NULL,identifier TEXT UNIQUE,description TEXT DEFAULT '',last_change DATETIME NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),min_x DOUBLE, min_y DOUBLE,max_x DOUBLE, max_y DOUBLE,srs_id INTEGER,CONSTRAINT fk_gc_r_srs_id FOREIGN KEY (srs_id) REFERENCES gpkg_spatial_ref_sys(srs_id)) |
7 |
-- end createTable
|
8 |
|
9 |
-- begin createTable
|
10 |
CREATE TABLE IF NOT EXISTS gpkg_extensions ( table_name TEXT, column_name TEXT, extension_name TEXT NOT NULL, definition TEXT NOT NULL, scope TEXT NOT NULL, CONSTRAINT ge_tce UNIQUE (table_name, column_name, extension_name) ) |
11 |
-- end createTable
|
12 |
|
13 |
-- begin createTable
|
14 |
CREATE TABLE IF NOT EXISTS "gpkg_geometry_columns" ( "table_name" TEXT NOT NULL, "column_name" TEXT NOT NULL, "geometry_type_name" TEXT NOT NULL, "srs_id" INTEGER NOT NULL, "z" TINYINT NOT NULL, "m" TINYINT NOT NULL, CONSTRAINT "pk_geom_cols" PRIMARY KEY("table_name","column_name"), CONSTRAINT "fk_gc_tn" FOREIGN KEY("table_name") REFERENCES "gpkg_contents"("table_name"), CONSTRAINT "uk_gc_table_name" UNIQUE("table_name"), CONSTRAINT "fk_gc_srs" FOREIGN KEY("srs_id") REFERENCES "gpkg_spatial_ref_sys"("srs_id") ) |
15 |
-- end createTable
|
16 |
|
17 |
-- begin createTable
|
18 |
INSERT INTO "gpkg_contents" ("table_name", "data_type", "identifier", "description", "last_change", "min_x", "min_y", "max_x", "max_y", "srs_id") VALUES ('test', 'features', 'test', '', '*', NULL, NULL, NULL, NULL, NULL) |
19 |
-- end createTable
|
20 |
|
21 |
-- begin createTable
|
22 |
CREATE TABLE "test" ("ID" INTEGER PRIMARY KEY NOT NULL, "Byte" TINYINT DEFAULT NULL, "Bool1" BOOLEAN DEFAULT NULL, "Long" BIGINT DEFAULT NULL, "Timestamp" DATETIME DEFAULT NULL, "Date" DATE DEFAULT NULL, "Time" TIME DEFAULT NULL, "Bool2" BOOLEAN DEFAULT NULL, "String" VARCHAR(30) DEFAULT NULL, "Bool3" BOOLEAN DEFAULT NULL, "Double" DOUBLE PRECISION DEFAULT NULL, "Bool4" BOOLEAN DEFAULT NULL, "Float" FLOAT DEFAULT NULL, "Bool5" BOOLEAN DEFAULT NULL, "Decimal" DECIMAL(6,3) DEFAULT NULL, "Geometry" BLOB DEFAULT NULL ) |
23 |
-- end createTable
|
24 |
|
25 |
-- begin createTable
|
26 |
INSERT INTO "gpkg_geometry_columns" ("table_name", "column_name", "geometry_type_name", "srs_id", "z", "m") VALUES ('test', 'Geometry', 'POINT', '4326', '0', '0') |
27 |
-- end createTable
|
28 |
|
29 |
-- begin createTable
|
30 |
CREATE TABLE IF NOT EXISTS gpkg_extensions ( table_name TEXT, column_name TEXT, extension_name TEXT NOT NULL, definition TEXT NOT NULL, scope TEXT NOT NULL, CONSTRAINT ge_tce UNIQUE (table_name, column_name, extension_name) ) |
31 |
-- end createTable
|
32 |
|
33 |
-- begin createTable
|
34 |
CREATE VIRTUAL TABLE "rtree_test_Geometry" USING rtree(id, minx, maxx, miny, maxy) |
35 |
-- end createTable
|
36 |
|
37 |
-- begin createTable
|
38 |
CREATE TRIGGER "rtree_test_Geometry_delete" AFTER DELETE ON "test" |
39 |
WHEN old."Geometry" NOT NULL |
40 |
BEGIN
|
41 |
DELETE FROM "rtree_test_Geometry" WHERE ID = OLD."ID"; |
42 |
END
|
43 |
-- end createTable
|
44 |
|
45 |
-- begin createTable
|
46 |
CREATE TRIGGER "rtree_test_Geometry_insert" AFTER INSERT ON "test" |
47 |
WHEN (new."Geometry" NOT NULL AND NOT ST_IsEmpty(NEW."Geometry")) |
48 |
BEGIN
|
49 |
INSERT OR REPLACE INTO "rtree_test_Geometry" VALUES ( |
50 |
NEW."ID",
|
51 |
ST_MinX(NEW."Geometry"), ST_MaxX(NEW."Geometry"), |
52 |
ST_MinY(NEW."Geometry"), ST_MaxY(NEW."Geometry") |
53 |
); |
54 |
END
|
55 |
-- end createTable
|
56 |
|
57 |
-- begin createTable
|
58 |
CREATE TRIGGER "rtree_test_Geometry_update1" AFTER UPDATE OF "Geometry" ON "test" |
59 |
WHEN OLD."ID" = NEW."ID" AND |
60 |
(NEW."Geometry" NOTNULL AND NOT ST_IsEmpty(NEW."Geometry")) |
61 |
BEGIN
|
62 |
INSERT OR REPLACE INTO "rtree_test_Geometry" VALUES ( |
63 |
NEW."ID",
|
64 |
ST_MinX(NEW."Geometry"), ST_MaxX(NEW."Geometry"), |
65 |
ST_MinY(NEW."Geometry"), ST_MaxY(NEW."Geometry") |
66 |
); |
67 |
END
|
68 |
-- end createTable
|
69 |
|
70 |
-- begin createTable
|
71 |
CREATE TRIGGER "rtree_test_Geometry_update2" AFTER UPDATE OF "Geometry" ON "test" |
72 |
WHEN OLD."ID" = NEW."ID" AND |
73 |
(NEW."Geometry" ISNULL OR ST_IsEmpty(NEW."Geometry")) |
74 |
BEGIN
|
75 |
DELETE FROM "rtree_test_Geometry" WHERE ID = OLD."ID"; |
76 |
END
|
77 |
-- end createTable
|
78 |
|
79 |
-- begin createTable
|
80 |
CREATE TRIGGER "rtree_test_Geometry_update3" AFTER UPDATE ON "test" |
81 |
WHEN OLD."ID" != NEW."ID" AND |
82 |
(NEW."Geometry" NOTNULL AND NOT ST_IsEmpty(NEW."Geometry")) |
83 |
BEGIN
|
84 |
DELETE FROM "rtree_test_Geometry" WHERE ID = OLD."ID"; |
85 |
INSERT OR REPLACE INTO "rtree_test_Geometry" VALUES ( |
86 |
NEW."ID",
|
87 |
ST_MinX(NEW."Geometry"), ST_MaxX(NEW."Geometry"), |
88 |
ST_MinY(NEW."Geometry"), ST_MaxY(NEW."Geometry") |
89 |
); |
90 |
END
|
91 |
-- end createTable
|
92 |
|
93 |
-- begin createTable
|
94 |
CREATE TRIGGER "rtree_test_Geometry_update4" AFTER UPDATE ON "test" |
95 |
WHEN OLD."ID" != NEW."ID" AND |
96 |
(NEW."Geometry" ISNULL OR ST_IsEmpty(NEW."Geometry")) |
97 |
BEGIN
|
98 |
DELETE FROM "rtree_test_Geometry" WHERE ID IN (OLD."ID", NEW."ID"); |
99 |
END
|
100 |
-- end createTable
|
101 |
|
102 |
-- begin createTable
|
103 |
INSERT INTO "gpkg_extensions" ( |
104 |
"table_name",
|
105 |
"column_name",
|
106 |
"extension_name",
|
107 |
"definition",
|
108 |
"scope"
|
109 |
) VALUES (
|
110 |
'test',
|
111 |
'Geometry',
|
112 |
'gpkg_rtree_index',
|
113 |
'http://www.geopackage.org/spec/#extension_rtree',
|
114 |
'read-write'
|
115 |
) |
116 |
-- end createTable
|