SQL_get_count.anubis
1.51 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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 25/03/2017
* Time: 01:57
* © Calexium
*/
read hayamiki_lib/types/hayamiki.anubis
read tools/basis.anubis
read tools/streams.anubis
read system/string.anubis
public define Maybe(One)
generate_get_count_by_clause
(
Stream stream,
HK_Table table
)=
since table is hk_table(name, short_name, model, _),
since model is hk_model(columns, _),
with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
//generate the type of the table that contain all components
if write_string(stream,
//SQL query
"public define Int\n"+
" get_count_"+name+"_by_clause\n"+
" (\n"+
" SQLite3DataBase db,\n"+
" String clause\n"+
" )=\n"+
" with final_clause = if clause = \"\" then\n"+
" \"\"\n"+
" else\n"+
" \"WHERE \"+clause,\n"+
"\n"+
" if sql_query_timeout(db, \"SELECT COUNT(\\\"id\\\") FROM "+name+" \"+final_clause+\";\", [], \"get_count_"+name+"_by_clause\") is\n"+
" {\n"+
" error(_) then 0,\n"+
" ok(_, cursor, _) then db_get_integer(cursor)\n"+
" }\n"+
".\n\n"
) is //end of the function
{
failure then println("can't write generate_get_all "+type_name); failure,
success(_) then success(unique)
}
.