diff --git a/extra/db2/db2.factor b/extra/db2/db2.factor index bda3d7ad70..e67cb8d200 100644 --- a/extra/db2/db2.factor +++ b/extra/db2/db2.factor @@ -8,49 +8,50 @@ IN: db2 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 [ execute-statement ] with-disposal ; +M: string sql-command ( string -- ) + f f sql-command ; -M: string sql-query ( sql -- sequence ) - f f [ statement>result-sequence ] with-disposal ; +M: string sql-query ( string -- sequence ) + f f sql-query ; -M: string sql-bind-command* ( sequence string -- ) - f f [ +M: statement sql-command ( statement -- ) + [ execute-statement ] with-disposal ; + +M: statement sql-query ( statement -- sequence ) + [ statement>result-sequence ] with-disposal ; + +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 [ +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 [ +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 [ +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 ; diff --git a/extra/db2/fql/fql.factor b/extra/db2/fql/fql.factor index e286e56a81..0896899b01 100644 --- a/extra/db2/fql/fql.factor +++ b/extra/db2/fql/fql.factor @@ -5,10 +5,8 @@ db2.private db2.sqlite.lib db2.statements db2.utils destructors 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 ; @@ -66,7 +64,7 @@ M: and expand-fql* ( obj -- string ) M: string expand-fql* ( string -- string ) ; M: insert expand-fql* - [ fql-statement new ] dip + [ statement new ] dip [ { [ "insert into " % into>> % ] @@ -77,7 +75,7 @@ M: insert expand-fql* ] "" make >>sql ; M: update expand-fql* - [ fql-statement new ] dip + [ statement new ] dip [ { [ "update " % tables>> ", " join % ] @@ -93,7 +91,7 @@ M: update expand-fql* ] "" make >>sql ; M: delete expand-fql* - [ fql-statement new ] dip + [ statement new ] dip [ { [ "delete from " % tables>> ", " join % ] @@ -104,7 +102,7 @@ M: delete expand-fql* ] "" make >>sql ; M: select expand-fql* - [ fql-statement new ] dip + [ statement new ] dip [ { [ "select " % names>> ", " join % ] @@ -116,21 +114,3 @@ M: select expand-fql* [ 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* ; diff --git a/extra/db2/result-sets/result-sets.factor b/extra/db2/result-sets/result-sets.factor index 6f69c26ab2..5bf148d4be 100644 --- a/extra/db2/result-sets/result-sets.factor +++ b/extra/db2/result-sets/result-sets.factor @@ -29,4 +29,4 @@ GENERIC# column-typed 1 ( result-set column -- sql ) dup #columns [ column ] with map ; : sql-row-typed ( result-set -- seq ) - dup #columns [ column-typed ] with map ; + dup #columns [ B column-typed ] with map ; diff --git a/extra/db2/sqlite/types/types.factor b/extra/db2/sqlite/types/types.factor index c8df3b2272..d2047c1aeb 100644 --- a/extra/db2/sqlite/types/types.factor +++ b/extra/db2/sqlite/types/types.factor @@ -85,13 +85,13 @@ IN: db2.sqlite.types [ 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 ; diff --git a/extra/db2/statements/statements-tests.factor b/extra/db2/statements/statements-tests.factor index 56c73211c9..6a4b774713 100644 --- a/extra/db2/statements/statements-tests.factor +++ b/extra/db2/statements/statements-tests.factor @@ -29,7 +29,8 @@ IN: db2.statements.tests [ { { "rocky" "mac" } } ] [ - "select name, os from computer;" sql-query + "select name, os from computer;" + f f sql-query ] unit-test [ "insert into" sql-command ] @@ -39,28 +40,30 @@ IN: db2.statements.tests [ sql-syntax-error? ] must-fail-with [ ] [ - { "clubber" "windows" } "insert into computer (name, os) values(?, ?);" - sql-bind-command* + { "clubber" "windows" } + f + sql-bind-command ] unit-test [ { { "windows" } } ] [ - { "clubber" } - "select os from computer where name = ?;" sql-bind-query* + "select os from computer where name = ?;" + { "clubber" } f 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 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 + sql-bind-typed-command ] unit-test diff --git a/extra/db2/statements/statements.factor b/extra/db2/statements/statements.factor index 989391473d..929b303d4b 100644 --- a/extra/db2/statements/statements.factor +++ b/extra/db2/statements/statements.factor @@ -16,8 +16,8 @@ HOOK: db-connection ( sql in out -- statement ) 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* ] @@ -47,3 +47,7 @@ M: object execute-statement* ( statement type -- ) : 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 ;