settings.anubis
2.22 KB
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
87
88
89
90
91
92
93
/*
* Created by PyramIDE.
* User: Steve Marechal
* Date: 09/12/2008
* Time: 17:19
*/
read tools/basis.anubis
read data_base/sqlite.anubis
read calexium_lib/database/db_utils.anubis
public define Maybe(String)
select_settings
(
SQLite3DataBase db,
String var,
)=
if sql_query_timeout(db, "SELECT var_value FROM settings WHERE var_name=" + db_make_sql_string(var) + ";", "select_settings") is
{
failure then failure, //error in the SQL request
success(table_cursor) then
if table_cursor(next_row) is
{
error(_) then failure,
no_more_row then failure, //can't find the var_value in the table, because the row is empty
row(current) then success(text(current)(0))
}
}.
public define String
select_settings
(
SQLite3DataBase db,
String var,
String default
)=
if select_settings(db, var) is
{
failure then default, //error in the SQL request
success(value) then value
}.
public define Int
select_settings
(
SQLite3DataBase db,
String var,
Int default
)=
if select_settings(db, var) is
{
failure then default, //error in the SQL request
success(value) then
if decimal_scan(value) is
{
failure then default,
success(v) then v
}
}.
public define Bool
select_settings
(
SQLite3DataBase db,
String var,
Bool default
)=
if select_settings(db, var) is
{
failure then default, //error in the SQL request
success(value) then
if decimal_scan(value) is
{
failure then default,
success(v) then v!=0
}
}.
public define One
update_settings
(
SQLite3DataBase db,
String var,
String value
)=
if select_settings(db, var) is success(_) then
forget(sql_query_timeout(db, "UPDATE settings SET var_value = @value WHERE var_name = @name;", [bind_String("@name", var), bind_String("@value", value)], "update_settings"))
else
forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (@name, @value)", [bind_String("@name", var), bind_String("@value", value)], "update_settings"))
.