-
Notifications
You must be signed in to change notification settings - Fork 13
/
MainView.ux
87 lines (79 loc) · 2.27 KB
/
MainView.ux
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<App>
<SQLite ux:Global="SQLite" />
<JavaScript>
var Observable = require('FuseJS/Observable');
var result = Observable('');
var insert_id = Observable('');
var select_id = Observable('');
var prepare_id = Observable('');
var sqlite = require('SQLite');
// var db = sqlite.open("file.sqlite");
// init_db();
var db = sqlite.openFromBundle('bundle.sqlite');
function init_db () {
db.execute("create table if not exists ids (id integer primary key)");
}
function insert_value () {
try {
db.execute("insert into ids values (?)", insert_id.value);
result.value="Insert successful";
}
catch (e) {
result.value = "Error inserting " + e;
}
}
function select_values () {
var r = '';
if (select_id.value != '') {
console.log("SELECT * WHERE id = " + select_id.value);
r = db.query("select * from ids WHERE id = ?", select_id.value);
}
else {
console.log("select * from ids");
r = db.query("select * from ids");
}
result.value = JSON.stringify(r);
debug_log(JSON.stringify(r));
}
function prepare_values () {
var r = '';
if (prepare_id.value != '') {
var stmnt = db.prepare("select * from ids WHERE id = ?")
r = stmnt.execute(prepare_id.value);
}
else {
console.log("select * from ids");
var stmnt = db.prepare("select * from ids");
r = stmnt.execute();
}
result.value = JSON.stringify(r);
debug_log(JSON.stringify(r));
}
module.exports = {
result: result,
init_db: init_db,
insert_value: insert_value,
select_values: select_values,
prepare_values: prepare_values,
insert_id: insert_id,
select_id: select_id,
prepare_id: prepare_id
}
</JavaScript>
<ClientPanel>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextInput Value="{insert_id}" Width="200" /><Button Text="Insert" Clicked="{insert_value}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextInput Value="{select_id}" Width="200" />
<Button Text="Select" Clicked="{select_values}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextInput Value="{prepare_id}" Width="200" />
<Button Text="Prepare" Clicked="{prepare_values}" />
</StackPanel>
<Text TextWrapping="Wrap" Value="{result}" />
</StackPanel>
</ClientPanel>
</App>