--- parser3/tests/388-sql.html 2017/12/06 20:19:16 1.2 +++ parser3/tests/388-sql.html 2024/12/12 20:35:57 1.22 @@ -1,29 +1,50 @@ -@main[] +@auto[] + +$path[^os[Release/;.libs/lib]] +$ext[^os[dll;so]] $SQL[ - $.drivers[^table::create{protocol driver client -sqlite ../../sql/sqlite/.libs/libparser3sqlite.so libsqlite3.so + $.drivers[^table::create{protocol driver client connect +sqlite ../../sql/sqlite/${path}parser3sqlite.$ext ^os[sqlite3.dll;libsqlite3.so] sqlite://:memory:?multi_statements=1 +mysql ../../sql/mysql/${path}parser3mysql.$ext ^os[libmySQL.dll;libmariadb.so.3] mysql://@/?config_group=parser3&multi_statements=1 +pgsql ../../sql/pgsql/${path}parser3pgsql.$ext libpq.$ext pgsql://test@localhost/test }] ] -^connect[sqlite://:memory:]{ - 1. 2 + 2 = ^string:sql{select 2+2} +$sql[sqlite] +$ignore[^SQL.drivers.locate[protocol;$sql]] +@prepare-data[] + $ignore[^try-catch{ ^void:sql{drop table pets} }] - 2. void + ^void:sql{create table pets (pet varchar(128), food varchar(128), aggressive varchar(128), weigth varchar(128))} - 2.1 ^void:sql{create table pets (pet varchar, food varchar, aggressive varchar, weigth varchar)} - - 2.2 ^void:sql{insert into pets values + ^void:sql{insert into pets values ('cat', 'milk', '^taint['very']', 5), ('dog', 'bone', '^taint["never"]', 10), + ('hamster', 'grain', null, 1), ('parrot', 'grain', 'alwayws', 1) - } + } + +@main[] + +^connect[$SQL.drivers.connect]{ + + 1. 2 + 2 = ^string:sql{select 2+2} + + + 2. void + + 2.1 ^prepare-data[] 2.3 ^try-catch{ ^void:sql{select * from pets} } 2.4 ^try-catch{ ^void:sql{query}[ $.unknown[yes] ] } 2.5 ^try-catch{ ^void:sql{query}[ $.bind[ $.name[value] ] ] } + 2.6 Multiple queries: ^try-catch{ ^void:sql{delete from pets where pet='' ^; delete from pets where pet=''} } + 2.8 Multiple queries, data in first query: ^if($sql ne 'mysql'){ ^try-catch{ ^void:sql{select 2+2 ^; delete from pets where pet=''} } } + 2.9 Multiple queries, data in second query: ^try-catch{ ^void:sql{delete from pets where pet='' ^; select 2+2} } + 3. int/double @@ -35,6 +56,10 @@ sqlite ../../sql/sqlite/.libs/libparser3 3.5 ^try-catch{ ^double:sql{select -2}[ $.limit(0) ] } 3.6 ^double:sql{select -2}[ $.limit(0) $.default[1] ] + 3.7 Multiple queries, data in first query: ^try-catch{ ^int:sql{select 2+2 ^; delete from pets where pet=''} } + 3.8 Multiple queries, data in second query: ^try-catch{ ^int:sql{delete from pets where pet='' ^; select 2+2} } + 3.9 Multiple queries, data in both queries: ^try-catch{ ^int:sql{select 2+2 ^; select 3+3 } } + 4. hash @@ -48,6 +73,16 @@ sqlite ../../sql/sqlite/.libs/libparser3 4.5. ^h[select * from pets; $.type[table] $.limit(1) $.offset(1) ] + 4.6 ^try-catch{ ^h[select 'dup', pet from pets; $.type[string] ]} + + 4.7 ^h[select pet from pets] + + 4.7.1 ^h[select aggressive from pets; $.type[table] ] + + 4.8 ^h[select food as id, pet from pets; $.type[table] $.distinct(true) ] + + 4.9 ^h[select food as id, pet from pets; $.type[string] $.distinct(true) ] + 5. table @@ -55,6 +90,10 @@ sqlite ../../sql/sqlite/.libs/libparser3 5.2. ^t[select * from pets; $.limit(1) $.offset(1) ] + 5.3 ^try-catch{ ^t[select * from pets; $.bind[ $.name[value] ] ] } + + 5.4 ^try-catch{ ^t[select * from pets; $.no-such-option[] ] } + 6. file @@ -66,7 +105,7 @@ sqlite ../../sql/sqlite/.libs/libparser3 6.4 ^try-catch{ ^f[select aggressive from pets; $.limit(0) ] } - 6.5 ^try-catch{ ^f[select 1 from pets] } - bug! + 6.5 ^try-catch{ ^f[select 1 from pets; $.limit(3) ] } 6.6 ^try-catch{ ^f[select 1,2 from pets] } @@ -74,6 +113,14 @@ sqlite ../../sql/sqlite/.libs/libparser3 6.8 $f[^file::create["'test'"]] ^f.sql-string[] + 7. string + + 7.1 ^try-catch{ ^s[select * from pets; $.limit(1) $.offset(1) ] } + 7.2 ^try-catch{ ^s[select pet from pets] } + 7.3 ^try-catch{ ^s[select 2+2; $.bind[ $.name[$value] ] ] } + 7.4 ^try-catch{ ^s[select 2+2; $.no-such-option[] ] } + 7.5 ^try-catch{ ^s[select pet from pets; $.limit(0) ] } + 7.6 ^s[select pet from pets; $.limit(0) $.default{default} ] } @@ -88,3 +135,10 @@ sqlite ../../sql/sqlite/.libs/libparser3 @f[query;options] $f[^file::sql{$query}[$options]] ^json:string[$f; $.indent(1) $.file[text] ] + +@s[query;options] + $s[^string:sql{$query}[$options]] + "$s" + +@postprocess[text] + $result[^taint[as-is;$text]]