-
Notifications
You must be signed in to change notification settings - Fork 13
/
SQLiteStatement.uno
70 lines (56 loc) · 1.6 KB
/
SQLiteStatement.uno
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
using Uno;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
using Bolav.ForeignHelpers;
public class SQLiteStatement : NativeModule
{
string statement;
public SQLiteStatement(string statement) {
this.statement = statement;
AddMember(new NativeFunction("execute", (NativeCallback)Execute));
}
extern (CIL) string db;
extern (iOS) IntPtr db;
extern (Android) Java.Object db;
extern (Uno) int db;
public extern(Uno) SQLiteStatement(int database, string statement) : this(statement) {
db = database;
}
public extern(CIL) SQLiteStatement(string database, string statement) : this(statement) {
db = database;
}
public extern(iOS) SQLiteStatement(IntPtr database, string statement) : this(statement) {
db = database;
}
public extern(Android) SQLiteStatement(Java.Object database, string statement) : this(statement) {
db = database;
}
// TODO: This is just a query now, and not prepared
object Execute(Context context, object[] args) {
var param_len = args.Length;
string[] param = new string[param_len];
for (var j=0; j < param_len; j++) {
param[j] = args[j] as string;
}
var jslist = new JSList(context);
if defined(!CIL) {
SQLiteImpl.QueryImpl(jslist, db, statement, param);
}
if defined(CIL) {
var result = SQLiteImpl.QueryImpl(db, statement, param);
int i = 0;
foreach (var row in result) {
var jsdict = jslist.NewDictRow();
foreach (var pair in row) {
string key = pair.Key as string;
string val = pair.Value as string;
jsdict.SetKeyVal(key,val);
}
i++;
}
}
return jslist.GetScriptingArray();
}
}