Annotation of parser3/tests/388-sql.html, revision 1.19
1.18 moko 1: @auto[]
1.2 moko 2:
1.13 moko 3: $path[^os[Release/;.libs/lib]]
4: $ext[^os[dll;so]]
5:
1.2 moko 6: $SQL[
1.8 moko 7: $.drivers[^table::create{protocol driver client connect
1.13 moko 8: sqlite ../../sql/sqlite/${path}parser3sqlite.$ext ^os[sqlite3.dll;libsqlite3.so] sqlite://:memory:?multi_statements=1
9: mysql ../../sql/mysql/${path}parser3mysql.$ext ^os[libmySQL.dll;libmariadbclient.so] mysql://@/?config_group=parser3&multi_statements=1
10: pgsql ../../sql/pgsql/${path}parser3pgsql.$ext libpq.$ext pgsql://test@localhost/test
1.2 moko 11: }]
12: ]
13:
1.11 moko 14: $sql[sqlite]
15: $ignore[^SQL.drivers.locate[protocol;$sql]]
1.8 moko 16:
1.18 moko 17: @prepare-data[]
18: $ignore[^try-catch{ ^void:sql{drop table pets} }]
19:
20: ^void:sql{create table pets (pet varchar(128), food varchar(128), aggressive varchar(128), weigth varchar(128))}
21:
22: ^void:sql{insert into pets values
23: ('cat', 'milk', '^taint['very']', 5),
24: ('dog', 'bone', '^taint["never"]', 10),
25: ('hamster', 'grain', null, 1),
26: ('parrot', 'grain', 'alwayws', 1)
27: }
28:
29: @main[]
30:
1.8 moko 31: ^connect[$SQL.drivers.connect]{
32:
1.1 moko 33: 1. 2 + 2 = ^string:sql{select 2+2}
34:
1.11 moko 35:
1.1 moko 36: 2. void
37:
1.18 moko 38: 2.1 ^prepare-data[]
1.1 moko 39:
40: 2.3 ^try-catch{ ^void:sql{select * from pets} }
41: 2.4 ^try-catch{ ^void:sql{query}[ $.unknown[yes] ] }
42: 2.5 ^try-catch{ ^void:sql{query}[ $.bind[ $.name[value] ] ] }
43:
1.11 moko 44: 2.6 Multiple queries: ^try-catch{ ^void:sql{delete from pets where pet='' ^; delete from pets where pet=''} }
45: 2.8 Multiple queries, data in first query: ^if($sql ne 'mysql'){ ^try-catch{ ^void:sql{select 2+2 ^; delete from pets where pet=''} } }
46: 2.9 Multiple queries, data in second query: ^try-catch{ ^void:sql{delete from pets where pet='' ^; select 2+2} }
47:
1.1 moko 48:
49: 3. int/double
50:
51: 3.1 $v(^int:sql{select 2}) $v $v.CLASS_NAME
52: 3.2 ^try-catch{ ^int:sql{select 2}[ $.limit(0) ] }
53: 3.3 ^int:sql{select 2}[ $.limit(0) $.default[1] ]
54:
55: 3.4 $v(^double:sql{select -2}) $v $v.CLASS_NAME
56: 3.5 ^try-catch{ ^double:sql{select -2}[ $.limit(0) ] }
57: 3.6 ^double:sql{select -2}[ $.limit(0) $.default[1] ]
58:
1.12 moko 59: 3.7 Multiple queries, data in first query: ^try-catch{ ^int:sql{select 2+2 ^; delete from pets where pet=''} }
1.11 moko 60: 3.8 Multiple queries, data in second query: ^try-catch{ ^int:sql{delete from pets where pet='' ^; select 2+2} }
61: 3.9 Multiple queries, data in both queries: ^try-catch{ ^int:sql{select 2+2 ^; select 3+3 } }
62:
1.1 moko 63:
64: 4. hash
65:
66: 4.1 ^h[select * from pets]
67:
68: 4.2 ^h[select * from pets; $.type[table]]
69:
70: 4.3 ^h[select pet, food from pets; $.type[string] ]
71:
72: 4.4 ^try-catch{ ^h[select * from pets; $.type[string] ]}
73:
74: 4.5. ^h[select * from pets; $.type[table] $.limit(1) $.offset(1) ]
75:
1.6 moko 76: 4.6 ^try-catch{ ^h[select 'dup', pet from pets; $.type[string] ]}
77:
1.15 moko 78: 4.7 ^h[select pet from pets]
79:
1.17 moko 80: 4.7.1 ^h[select aggressive from pets; $.type[table] ]
1.16 moko 81:
1.17 moko 82: 4.8 ^h[select food as key, pet from pets; $.type[table] $.distinct(true) ]
83:
84: 4.9 ^h[select food as key, pet from pets; $.type[string] $.distinct(true) ]
1.16 moko 85:
1.1 moko 86:
87: 5. table
88:
89: 5.1 ^t[select * from pets]
90:
91: 5.2. ^t[select * from pets; $.limit(1) $.offset(1) ]
92:
1.4 moko 93: 5.3 ^try-catch{ ^t[select * from pets; $.bind[ $.name[value] ] ] }
94:
95: 5.4 ^try-catch{ ^t[select * from pets; $.no-such-option[] ] }
96:
1.1 moko 97:
98: 6. file
99:
100: 6.1 ^f[select aggressive,'test.txt' from pets; $.limit(1) $.content-type[text/plain] ]
101:
102: 6.2 ^f[select aggressive,'test.txt','unknown' from pets; $.limit(1) $.name[unknown] $.offset(1) ]
103:
104: 6.3 ^try-catch{ ^f[select * from pets; $.limit(1) ] }
105:
106: 6.4 ^try-catch{ ^f[select aggressive from pets; $.limit(0) ] }
107:
1.19 ! moko 108: 6.5 ^try-catch{ ^f[select 1 from pets; $.limit(3) ] }
1.1 moko 109:
110: 6.6 ^try-catch{ ^f[select 1,2 from pets] }
111:
112: 6.7 ^try-catch{ ^f[select aggressive from pets; $.unknown[yes] ] }
113:
114: 6.8 $f[^file::create["'test'"]] ^f.sql-string[]
115:
1.3 moko 116: 7. string
117:
118: 7.1 ^try-catch{ ^s[select * from pets; $.limit(1) $.offset(1) ] }
119: 7.2 ^try-catch{ ^s[select pet from pets] }
120: 7.3 ^try-catch{ ^s[select 2+2; $.bind[ $.name[$value] ] ] }
121: 7.4 ^try-catch{ ^s[select 2+2; $.no-such-option[] ] }
122: 7.5 ^try-catch{ ^s[select pet from pets; $.limit(0) ] }
123: 7.6 ^s[select pet from pets; $.limit(0) $.default{default} ]
1.1 moko 124:
125: }
126:
127: @h[query;options]
128: $h[^hash::sql{$query}[$options]]
129: ^json:string[$h; $.indent(1) ]
130:
131: @t[query;options]
132: $t[^table::sql{$query}[$options]]
133: ^json:string[$t; $.indent(1) ]
134:
135: @f[query;options]
136: $f[^file::sql{$query}[$options]]
137: ^json:string[$f; $.indent(1) $.file[text] ]
1.3 moko 138:
139: @s[query;options]
140: $s[^string:sql{$query}[$options]]
141: "$s"
1.14 moko 142:
143: @postprocess[text]
144: $result[^taint[as-is;$text]]
E-mail: