1 module test;
2 
3 //          Copyright Stefan Koch 2015 - 2018.
4 // Distributed under the Boost Software License, Version 1.0.
5 //    (See accompanying file LICENSE.md or copy at
6 //          http://www.boost.org/LICENSE_1_0.txt)
7 
8 import sqlited;
9 import misc;
10 import sqlstuff;
11 
12 static immutable long_create_table = 
13 q{CREATE TABLE `veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongtttttttttaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbllllllllllleeeeeeeeeeeeeeeeennnnnnaaaaaaaaaaameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee` (
14 	`vvvvvvvvvveeeeeeeerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyylllllllloooooooooooooooooooooooooooonnnnnnnnnnnnnnnngggggggggggggggggggvvvvvvvvvvvvvvvvffffffffffffffffffffiiiiiiiiiiieeeeeeeeeeeeeeeeellllllllllllllddddddddddddddddddddddnnnnnnnnnnnaaaaaaaaaaaaammmmmmmmmmmmmmmmeeeeeeeeeeeeeeeeee`	INTEGER,
15 	`Field2`	INTEGER
16 )};
17 static immutable test_s3db = cast(immutable)Database(cast(immutable ubyte[]) import("test.s3db"));
18 static immutable Database.MasterTableSchema[] schemas = readRows!(r => r.deserialize!(Database.MasterTableSchema))(test_s3db.rootPage, test_s3db.pages);
19 static assert(schemas[2].sql==long_create_table);
20 
21 import frail_sql_parser;
22 
23 static assert (parseCreateTable(
24 	q{CREATE TABLE spatial_ref_sys (
25 		srid INTEGER NOT NULL PRIMARY KEY,
26 		auth_name VARCHAR(256) NOT NULL,
27 		auth_srid INTEGER NOT NULL,
28 		ref_sys_name VARCHAR(256),
29 		proj4text VARCHAR(2048) NOT NULL)}
30 	) == TableInfo("spatial_ref_sys", [
31 			ColumInfo("srid", "INTEGER", true, true),
32 			ColumInfo("auth_name", "VARCHAR(256)", false, true),
33 			ColumInfo("auth_srid", "INTEGER", false, true),
34 			ColumInfo("ref_sys_name","VARCHAR(256)",false),
35 			ColumInfo("proj4text","VARCHAR(2048)", false, true),
36 	])
37 );
38 static assert(parseCreateTable(long_create_table) == TableInfo("veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongtttttttttaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbllllllllllleeeeeeeeeeeeeeeeennnnnnaaaaaaaaaaameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", [ColumInfo("vvvvvvvvvveeeeeeeerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyylllllllloooooooooooooooooooooooooooonnnnnnnnnnnnnnnngggggggggggggggggggvvvvvvvvvvvvvvvvffffffffffffffffffffiiiiiiiiiiieeeeeeeeeeeeeeeeellllllllllllllddddddddddddddddddddddnnnnnnnnnnnaaaaaaaaaaaaammmmmmmmmmmmmmmmeeeeeeeeeeeeeeeeee", "INTEGER"), ColumInfo("Field2", "INTEGER")]));
39 
40 static assert(parseCreateTable(
41 q{CREATE TABLE Towns (
42 				PK_UID INTEGER PRIMARY KEY AUTOINCREMENT,
43 				Name TEXT,
44 				Peoples INTEGER,
45 				LocalCounc INTEGER,
46 				County INTEGER,
47 				Region INTEGER, "Geometry" POINT)
48 }
49 	) == TableInfo("Towns", [
50 		ColumInfo("PK_UID", "INTEGER", true, false, false, true), 
51 		ColumInfo("Name", "TEXT"),
52 		ColumInfo("Peoples", "INTEGER"), 
53 		ColumInfo("LocalCounc", "INTEGER"), 
54 		ColumInfo("County", "INTEGER"), 
55 		ColumInfo("Region", "INTEGER"), 
56 		ColumInfo("Geometry", "POINT")
57 	])
58 );