]> gitweb.factorcode.org Git - factor.git/commitdiff
refactor sqlite bind
authorDoug Coleman <erg@jobim.local>
Mon, 13 Apr 2009 22:40:35 +0000 (17:40 -0500)
committerDoug Coleman <erg@jobim.local>
Mon, 13 Apr 2009 22:40:35 +0000 (17:40 -0500)
extra/db2/db2.factor
extra/db2/sqlite/lib/lib.factor

index 708caa97ab81f519d57ba8a5137262d8f012b0be..8278d18598996ccf770ccc2294b8d57e2aa52e9e 100644 (file)
@@ -23,7 +23,7 @@ PRIVATE>
 : sql-bind-command ( sequence string -- )
     f f <statement> [
         sqlite-maybe-prepare [
-            handle>> '[ [ _ ] 2dip 1+ swap sqlite-bind-text ] each-index
+            handle>> swap sqlite-bind-sequence
         ] [
             sqlite-result-set new-result-set advance-row
         ] bi
@@ -32,7 +32,7 @@ PRIVATE>
 : sql-bind-query ( in-sequence string -- out-sequence )
     f f <statement> [
         sqlite-maybe-prepare [
-            handle>> '[ [ _ ] 2dip 1+ swap sqlite-bind-text ] each-index
+            handle>> swap sqlite-bind-sequence
         ] [
             statement>result-sequence
         ] bi
index 34918efb8de94bf9517908f969c42158557c2d08..26c56cbbd244aa0c3e1bfdb2d17e193735c460f2 100644 (file)
@@ -8,6 +8,9 @@ IN: db2.sqlite.lib
 
 : ?when ( object quot -- object' ) dupd when ; inline
 
+: assoc-with ( object sequence quot -- obj curry )
+    swapd [ [ -rot ] dip  call ] 2curry ; inline
+
 : sqlite-check-result ( n -- )
     {
         { SQLITE_OK [ ] }
@@ -107,3 +110,6 @@ 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 ;