more generics in the statement protocol

db4
Doug Coleman 2009-04-13 18:19:37 -05:00
parent 6db0999775
commit 66a4ec5896
5 changed files with 26 additions and 30 deletions

View File

@ -23,36 +23,24 @@ PRIVATE>
: sql-bind-command ( sequence string -- )
f f <statement> [
sqlite-maybe-prepare [
handle>> swap sqlite-bind-sequence
] [
>sqlite-result-set drop
] bi
prepare-statement
[ bind-sequence ] [ statement>result-set drop ] bi
] with-disposal ;
: sql-bind-query ( in-sequence string -- out-sequence )
f f <statement> [
sqlite-maybe-prepare [
handle>> swap sqlite-bind-sequence
] [
statement>result-sequence
] bi
prepare-statement
[ bind-sequence ] [ statement>result-sequence ] bi
] with-disposal ;
: sql-bind-typed-command ( in-sequence string -- )
f f <statement> [
sqlite-maybe-prepare [
handle>> swap sqlite-bind-typed-sequence
] [
>sqlite-result-set drop
] bi
prepare-statement
[ bind-typed-sequence ] [ statement>result-set drop ] bi
] with-disposal ;
: sql-bind-typed-query ( in-sequence string -- out-sequence )
f f <statement> [
sqlite-maybe-prepare [
handle>> swap sqlite-bind-typed-sequence
] [
statement>result-sequence
] bi
prepare-statement
[ bind-typed-sequence ] [ statement>result-sequence ] bi
] with-disposal ;

View File

@ -114,8 +114,5 @@ IN: db2.sqlite.lib
: sqlite-next ( prepared -- ? )
sqlite3_step sqlite-step-has-more-rows? ;
: sqlite-bind-sequence ( handle sequence -- )
[ 1+ swap sqlite-bind-text ] assoc-with each-index ;
: >sqlite-result-set ( statement -- result-set )
sqlite-result-set new-result-set dup advance-row ;

View File

@ -14,8 +14,6 @@ M: sqlite-statement dispose
handle>>
[ [ sqlite3_reset drop ] [ sqlite-finalize ] bi ] when* ;
: sqlite-maybe-prepare ( statement -- statement )
dup handle>> [
db-connection get handle>> over sql>> sqlite-prepare
>>handle
] unless ;
M: sqlite-statement prepare-statement* ( statement -- statement )
db-connection get handle>> over sql>> sqlite-prepare
>>handle ;

View File

@ -84,5 +84,12 @@ IN: db2.sqlite.types
[ no-sql-type ]
} case ;
: sqlite-bind-typed-sequence ( handle sequence -- )
[ 1+ swap first2 swap bind-next-sqlite-type ] assoc-with each-index ;
M: sqlite-statement bind-sequence ( sequence statement -- )
handle>> '[
[ _ ] 2dip 1+ swap sqlite-bind-text
] each-index ;
M: sqlite-statement bind-typed-sequence ( sequence statement -- )
handle>> '[
[ _ ] 2dip 1+ swap first2 swap bind-next-sqlite-type
] each-index ;

View File

@ -15,6 +15,9 @@ TUPLE: statement handle sql in out type ;
HOOK: <statement> 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 -- )
: statement>result-set ( statement -- result-set )
[ statement>result-set* ]
@ -31,6 +34,9 @@ M: object execute-statement* ( statement type -- )
[ [ execute-one-statement ] each ]
[ execute-one-statement ] if ;
: prepare-statement ( statement -- statement )
dup handle>> [ prepare-statement* ] unless ;
: statement-each ( statement quot: ( statement -- ) -- )
over more-rows?
[ [ call ] 2keep over advance-row statement-each ]