GENERIC: sql-command ( object -- )
GENERIC: sql-query ( object -- sequence )
-GENERIC: sql-bind-command* ( sequence object -- )
-GENERIC: sql-bind-query* ( sequence object -- sequence )
-GENERIC: sql-bind-typed-command* ( sequence object -- )
-GENERIC: sql-bind-typed-query* ( sequence object -- sequence )
-
GENERIC: sql-bind-command ( object -- )
GENERIC: sql-bind-query ( object -- sequence )
GENERIC: sql-bind-typed-command ( object -- )
GENERIC: sql-bind-typed-query ( object -- sequence )
-M: string sql-command ( sql -- )
- f f <statement> [ execute-statement ] with-disposal ;
+M: string sql-command ( string -- )
+ f f <statement> sql-command ;
+
+M: string sql-query ( string -- sequence )
+ f f <statement> sql-query ;
+
+M: statement sql-command ( statement -- )
+ [ execute-statement ] with-disposal ;
-M: string sql-query ( sql -- sequence )
- f f <statement> [ statement>result-sequence ] with-disposal ;
+M: statement sql-query ( statement -- sequence )
+ [ statement>result-sequence ] with-disposal ;
-M: string sql-bind-command* ( sequence string -- )
- f f <statement> [
+M: statement sql-bind-command ( statement -- )
+ [
prepare-statement
[ bind-sequence ] [ statement>result-set drop ] bi
] with-disposal ;
-M: string sql-bind-query* ( in-sequence string -- out-sequence )
- f f <statement> [
+M: statement sql-bind-query ( statement -- sequence )
+ [
prepare-statement
[ bind-sequence ] [ statement>result-sequence ] bi
] with-disposal ;
-M: string sql-bind-typed-command* ( in-sequence string -- )
- f f <statement> [
+M: statement sql-bind-typed-command ( statement -- )
+ [
prepare-statement
[ bind-typed-sequence ] [ statement>result-set drop ] bi
] with-disposal ;
-M: string sql-bind-typed-query* ( in-sequence string -- out-sequence )
- f f <statement> [
+M: statement sql-bind-typed-query ( statement -- sequence )
+ [
prepare-statement
[ bind-typed-sequence ] [ statement>result-sequence ] bi
] with-disposal ;
M: sequence sql-command [ sql-command ] each ;
M: sequence sql-query [ sql-query ] map ;
-M: sequence sql-bind-command* [ sql-bind-command* ] with each ;
-M: sequence sql-bind-query* [ sql-bind-query* ] with map ;
-M: sequence sql-bind-typed-command* [ sql-bind-typed-command* ] with each ;
-M: sequence sql-bind-typed-query* [ sql-bind-typed-query* ] with map ;
+M: sequence sql-bind-command [ sql-bind-command ] each ;
+M: sequence sql-bind-query [ sql-bind-query ] map ;
+M: sequence sql-bind-typed-command [ sql-bind-typed-command ] each ;
+M: sequence sql-bind-typed-query [ sql-bind-typed-query ] map ;
kernel make math.parser sequences strings assocs db2.utils ;
IN: db2.fql
-TUPLE: fql-statement sql in out ;
-
-GENERIC: expand-fql* ( object -- sequence/fql-statement )
-GENERIC: normalize-fql ( object -- sequence/fql-statement )
+GENERIC: expand-fql* ( object -- sequence/statement )
+GENERIC: normalize-fql ( object -- sequence/statement )
! M: object normalize-fql ;
M: string expand-fql* ( string -- string ) ;
M: insert expand-fql*
- [ fql-statement new ] dip
+ [ statement new ] dip
[
{
[ "insert into " % into>> % ]
] "" make >>sql ;
M: update expand-fql*
- [ fql-statement new ] dip
+ [ statement new ] dip
[
{
[ "update " % tables>> ", " join % ]
] "" make >>sql ;
M: delete expand-fql*
- [ fql-statement new ] dip
+ [ statement new ] dip
[
{
[ "delete from " % tables>> ", " join % ]
] "" make >>sql ;
M: select expand-fql*
- [ fql-statement new ] dip
+ [ statement new ] dip
[
{
[ "select " % names>> ", " join % ]
[ limit>> [ " limit " % # ] when* ]
} cleave
] "" make >>sql ;
-
-M: fql-statement sql-command ( sql -- )
- sql>> sql-command ;
-
-M: fql-statement sql-query ( sql -- sequence )
- sql>> sql-query ;
-
-M: fql-statement sql-bind-command ( fql-statement -- )
- [ in>> ] [ sql>> ] bi sql-bind-command* ;
-
-M: fql-statement sql-bind-query ( fql-statement -- out-sequence )
- [ in>> ] [ sql>> ] bi sql-bind-query* ;
-
-M: fql-statement sql-bind-typed-command ( string -- )
- [ in>> ] [ sql>> ] bi sql-bind-typed-command* ;
-
-M: fql-statement sql-bind-typed-query ( string -- out-sequence )
- [ in>> ] [ sql>> ] bi sql-bind-typed-query* ;
dup #columns [ column ] with map ;
: sql-row-typed ( result-set -- seq )
- dup #columns [ column-typed ] with map ;
+ dup #columns [ B column-typed ] with map ;
[ no-sql-type ]
} case ;
-M: sqlite-statement bind-sequence ( sequence statement -- )
- handle>> '[
+M: sqlite-statement bind-sequence ( statement -- )
+ [ in>> ] [ handle>> ] bi '[
[ _ ] 2dip 1+ swap sqlite-bind-text
] each-index ;
-M: sqlite-statement bind-typed-sequence ( sequence statement -- )
- handle>> '[
+M: sqlite-statement bind-typed-sequence ( statement -- )
+ [ in>> ] [ handle>> ] bi '[
[ _ ] 2dip 1+ swap first2 swap bind-next-sqlite-type
] each-index ;
[ { { "rocky" "mac" } } ]
[
- "select name, os from computer;" sql-query
+ "select name, os from computer;"
+ f f <statement> sql-query
] unit-test
[ "insert into" sql-command ]
[ sql-syntax-error? ] must-fail-with
[ ] [
- { "clubber" "windows" }
"insert into computer (name, os) values(?, ?);"
- sql-bind-command*
+ { "clubber" "windows" }
+ f <statement>
+ sql-bind-command
] unit-test
[ { { "windows" } } ] [
- { "clubber" }
- "select os from computer where name = ?;" sql-bind-query*
+ "select os from computer where name = ?;"
+ { "clubber" } f <statement> sql-bind-query
] unit-test
[ { { "windows" } } ] [
+ "select os from computer where name = ?;"
{ { VARCHAR "clubber" } }
- "select os from computer where name = ?;" sql-bind-typed-query*
+ f <statement> sql-bind-typed-query
] unit-test
[ ] [
+ "insert into computer (name, os) values(?, ?);"
{
{ VARCHAR "clubber" }
{ VARCHAR "windows" }
- }
- "insert into computer (name, os) values(?, ?);"
- sql-bind-typed-command*
+ } f <statement>
+ sql-bind-typed-command
] unit-test
GENERIC: statement>result-set* ( statement -- result-set )
GENERIC: execute-statement* ( statement type -- )
GENERIC: prepare-statement* ( statement -- statement' )
-GENERIC: bind-sequence ( sequence statement -- )
-GENERIC: bind-typed-sequence ( sequence statement -- )
+GENERIC: bind-sequence ( statement -- )
+GENERIC: bind-typed-sequence ( statement -- )
: statement>result-set ( statement -- result-set )
[ statement>result-set* ]
: statement>result-sequence ( statement -- sequence )
statement>result-set [ [ sql-row ] statement-map ] with-disposal ;
+
+: statement>typed-result-sequence ( statement -- sequence )
+ [ out>> ] [ statement>result-set ] bi
+ [ [ sql-row-typed ] with statement-map ] with-disposal ;