File:  [parser3project] / parser3 / tests / 388-sql.html
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Wed Sep 11 15:58:37 2019 UTC (6 years, 11 months ago) by moko
Branches: MAIN
CVS tags: HEAD
+duplicate key exception test

@main[]

$SQL[
	$.drivers[^table::create{protocol	driver	client
sqlite	../../sql/sqlite/.libs/libparser3sqlite.so	libsqlite3.so
}]
]

^connect[sqlite://:memory:]{
	1. 2 + 2 = ^string:sql{select 2+2}


	2. void

	2.1 ^void:sql{create table pets (pet varchar(128), food varchar(128), aggressive varchar(128), weigth varchar(128))}

	2.2 ^void:sql{insert into pets values
		('cat', 'milk', '^taint['very']', 5),
		('dog', 'bone', '^taint["never"]', 10),
		('parrot', 'grain', 'alwayws', 1)
	   }

	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] ] ] }


	3. int/double

	3.1 $v(^int:sql{select 2}) $v $v.CLASS_NAME
	3.2 ^try-catch{ ^int:sql{select 2}[ $.limit(0) ] }
	3.3 ^int:sql{select 2}[ $.limit(0) $.default[1] ]

	3.4 $v(^double:sql{select -2}) $v $v.CLASS_NAME
	3.5 ^try-catch{ ^double:sql{select -2}[ $.limit(0) ] }
	3.6 ^double:sql{select -2}[ $.limit(0) $.default[1] ]


	4. hash

	4.1 ^h[select * from pets]

	4.2 ^h[select * from pets; $.type[table]]

	4.3 ^h[select pet, food from pets; $.type[string] ]

	4.4 ^try-catch{ ^h[select * from pets; $.type[string] ]}

	4.5. ^h[select * from pets; $.type[table] $.limit(1) $.offset(1) ]

	4.6 ^try-catch{ ^h[select 'dup', pet from pets; $.type[string] ]}


	5. table

	5.1 ^t[select * from pets]

	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

	6.1 ^f[select aggressive,'test.txt' from pets; $.limit(1) $.content-type[text/plain] ]

	6.2 ^f[select aggressive,'test.txt','unknown' from pets; $.limit(1) $.name[unknown] $.offset(1) ]

	6.3 ^try-catch{ ^f[select * from pets; $.limit(1) ] }

	6.4 ^try-catch{ ^f[select aggressive from pets; $.limit(0) ] }

	6.5 ^try-catch{ ^f[select 1 from pets] } - bug!

	6.6 ^try-catch{ ^f[select 1,2 from pets] }

	6.7 ^try-catch{ ^f[select aggressive from pets; $.unknown[yes] ] }

	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} ]

}

@h[query;options]
	$h[^hash::sql{$query}[$options]]
	^json:string[$h; $.indent(1) ]

@t[query;options]
	$t[^table::sql{$query}[$options]]
	^json:string[$t; $.indent(1) ]

@f[query;options]
	$f[^file::sql{$query}[$options]]
	^json:string[$f; $.indent(1) $.file[text] ]

@s[query;options]
	$s[^string:sql{$query}[$options]]
	"$s"

E-mail: