This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Main.hx
69 lines (51 loc) · 1.67 KB
/
Main.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package;
// http://api.haxe.org/sys/db/Sqlite.html
// http://api.haxe.org/sys/db/Connection.html
// http://api.haxe.org/sys/db/ResultSet.html
import sys.db.*;
class Main {
public static function main () {
var conn = null;
try {
conn = Sqlite.open("test.db");
}
catch (e:Dynamic) {
trace('Connection failed with error: $e');
}
if (conn != null) {
trace('Connected to database ${conn.dbName()}');
conn.request("
CREATE TABLE IF NOT EXISTS sdttbl (
intcol INT NULL,
dblcol DOUBLE NULL,
strcol VARCHAR(45) NULL,
datecol DATETIME NULL
)
");
conn.request('INSERT INTO sdttbl (intcol, dblcol, strcol, datecol) VALUES (123, 3.14, "test string", "${Date.now()}")'); // insert row with columns: int, double, string and date.
var dbRes = conn.request('SELECT * FROM sdttbl');
trace('Read records count: ${dbRes.length}');
trace('Read columns count: ${dbRes.nfields}');
trace('Read field names: ${dbRes.getFieldsNames()}');
var results = dbRes.results();
trace('Display results v1:');
trace('null');
// don't work with SQLite: https://github.com/HaxeFoundation/haxe/issues/6577#issuecomment-330144622
/*
for (res in results) {
for (fld in dbRes.getFieldsNames())
Sys.print('$fld: ${Reflect.field(res, fld)}, ');
Sys.println('');
}
*/
trace('Display results v2:');
for (res in results) {
Sys.print('intcol: ${res.intcol}, ');
Sys.print('dblcol: ${res.dbcol}, ');
Sys.print('strcol: ${res.strcol}, ');
Sys.println('datecol: ${res.datecol}, ');
}
conn.close();
}
}
}