egra: slightly different blending code
[iv.d.git] / sq3 / sq3_test1.d
blob628f5f200d8f61b8a77ffff0a7bd28563286116e
1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module sq3_test /*is aliced*/;
19 import iv.alice;
20 import iv.sq3;
21 import iv.strex;
22 import iv.vfs;
23 import iv.vfs.io;
26 static immutable schema =
27 "PRAGMA auto_vacuum = NONE;\n"~
28 "PRAGMA journal_mode = MEMORY; /*MEMORY;*/ /*PERSIST;*/ /*WAL;*/ /*MEMORY;*/\n"~
29 "PRAGMA synchronous = OFF;\n"~
30 "PRAGMA encoding = \"UTF-8\";\n"~
31 "\n"~
32 "CREATE TABLE IF NOT EXISTS test(\n"~
33 " id INTEGER PRIMARY KEY\n"~
34 " , text TEXT\n"~
35 ");\n"~
36 "\n"~
37 "CREATE UNIQUE INDEX IF NOT EXISTS testindex ON test(text);\n"~
38 "";
43 ////////////////////////////////////////////////////////////////////////////////
44 void main () {
45 try { import std.file : remove; remove("test.db"); } catch (Exception) {}
47 writeln("opening db...");
48 auto db = Database("test.db", schema);
49 writeln("starting the transaction");
50 db.execute("begin transaction;");
51 writeln("creating the statement");
52 auto stmt = db.statement("INSERT INTO test (id,text) VALUES(NULL,:text);");
53 writeln("binding");
54 stmt.bind(":text", n"ÈÕÊ!");
55 writeln("executing");
56 stmt.doAll();
57 writeln("binding");
58 stmt.bind(":text", n"ÐÉÚÄÁ!");
59 writeln("executing");
60 stmt.doAll();
61 writeln("binding");
62 stmt.bind(":text", n"ÒÁÚ-Ä×Á!");
63 writeln("executing");
64 stmt.doAll();
65 writeln("commiting the transaction");
66 db.execute("commit transaction;");
68 auto stx = db.statement("SELECT text AS text FROM test WHERE :a=:a;");
69 auto sty = stx;
70 foreach (auto row; sty.bindConstText(":a", "boo!").range) {
71 import std.conv : to;
72 writeln("idx=", row.index_, "; type=", row.text!DBFieldType, "; val=<", row.text!SQ3Text, ">");
74 writeln("char[]");
75 char[] cc = row.text!(char[]);
76 writeln("SQ3Text");
77 SQ3Text ct = row.text!SQ3Text;
78 writeln("string");
79 string cs = row.text!string;
83 writeln("closing the db");
84 db.close();