]> gitweb.factorcode.org Git - factor.git/commitdiff
refactoring the db protocol, remove fql-statements
authorDoug Coleman <erg@jobim.local>
Tue, 14 Apr 2009 21:14:40 +0000 (16:14 -0500)
committerDoug Coleman <erg@jobim.local>
Tue, 14 Apr 2009 21:14:40 +0000 (16:14 -0500)
extra/db2/db2.factor
extra/db2/fql/fql.factor
extra/db2/result-sets/result-sets.factor
extra/db2/sqlite/types/types.factor
extra/db2/statements/statements-tests.factor
extra/db2/statements/statements.factor

index bda3d7ad70f3d6699738d6dce3dbc74ce472fb63..e67cb8d200e8f98ea28205bfe313a60906e3dd75 100644 (file)
@@ -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 <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 ;
index e286e56a81dd92e9857c0f098ab90961a2ce99b0..0896899b01b5ea61fd01511fe8c7f80f10115523 100644 (file)
@@ -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* ;
index 6f69c26ab2b629fc0574acf5e008afe19146566e..5bf148d4bedb53d3f7dc05ae67296556e82769da 100644 (file)
@@ -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 [ column-typed ] with map ;
index c8df3b22727139189710d07ac711b4fb5d381cdf..d2047c1aebd0a050299813b6b3a16c8c7598b198 100644 (file)
@@ -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 ;
 
index 56c73211c94cf83b61ea04755300446048687399..6a4b774713f70e99ecdaf8607f6b76cae1ef7465 100644 (file)
@@ -29,7 +29,8 @@ IN: db2.statements.tests
     
     [ { { "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 ]
@@ -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 <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
 
 
index 989391473dbd62a0396d41a59be33f738375c6d7..929b303d4b9817c4af2f69d687df9e63c77feb5c 100644 (file)
@@ -16,8 +16,8 @@ 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 -- )
+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 ;