]> gitweb.factorcode.org Git - factor.git/commitdiff
more work on db2
authorDoug Coleman <erg@jobim.local>
Sun, 12 Apr 2009 01:21:04 +0000 (20:21 -0500)
committerDoug Coleman <erg@jobim.local>
Sun, 12 Apr 2009 01:21:04 +0000 (20:21 -0500)
extra/db2/connections/connections.factor
extra/db2/pools/pools-tests.factor
extra/db2/pools/pools.factor
extra/db2/sqlite/sqlite.factor
extra/db2/transactions/transactions.factor

index c622f9a4b4a7b01a1b4dcb6914dafdabe8445ebe..faea6406fe9a13e9d86c614b2dbe2287ac28a8e9 100644 (file)
@@ -5,13 +5,19 @@ IN: db2.connections
 
 TUPLE: db-connection handle ;
 
+: new-db-connection ( handle class -- db-connection )
+    new
+        swap >>handle ; inline
+
 GENERIC: db-open ( db -- db-connection )
-HOOK: db-close db-connection ( handle -- )
+
+GENERIC: db-close ( handle  -- )
+
 HOOK: parse-db-error db-connection ( error -- error' )
 
 M: db-connection dispose ( db-connection -- )
-    [ db-close f ] change-handle drop ;
+    [ db-close ] [ f >>handle drop ] bi ;
 
 : with-db ( db quot -- )
-    [ db-open db-connection dup ] dip
+    [ db-open db-connection over ] dip
     '[ _ [ drop @ ] with-disposal ] with-variable ; inline
index 7ff2a33d92239fcba935a00cd5c72726953b4d38..d61b745b031583a06e4ff2bd2b788efef4f636b2 100644 (file)
@@ -1,6 +1,8 @@
-IN: db.pools.tests
-USING: db.pools tools.test continuations io.files io.files.temp
-io.directories namespaces accessors kernel math destructors ;
+USING: accessors continuations db2.pools db2.sqlite
+db2.sqlite.connections destructors io.directories io.files
+io.files.temp kernel math namespaces tools.test
+db2.sqlite.connections ;
+IN: db2.pools.tests
 
 \ <db-pool> must-infer
 
@@ -9,7 +11,6 @@ io.directories namespaces accessors kernel math destructors ;
 { 1 0 } [ [ ] with-pooled-db ] must-infer-as
 
 ! Test behavior after image save/load
-USE: db.sqlite
 
 [ "pool-test.db" temp-file delete-file ] ignore-errors
 
index b22dbde398e62267e0bfd1e9760f4402ba79f4a0..2b1aa2f0bf1105c7daf27a4ff1fea14e07a31629 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors db2.connections fry io.pools kernel
 namespaces ;
-IN: db.pools
+IN: db2.pools
 
 TUPLE: db-pool < pool db ;
 
index edb74dd06f1502dedc9d869ddaa74184fd992598..82337ae30ba203b68da7c8ce722f1cacee244197 100644 (file)
@@ -1,4 +1,12 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: ;
+USING: constructors db2.connections ;
 IN: db2.sqlite
+
+TUPLE: sqlite-db path ;
+CONSTRUCTOR: sqlite-db ( path -- sqlite-db ) ;
+
+TUPLE: sqlite-db-connection < db-connection ;
+
+: <sqlite-db-connection> ( handle -- db-connection )
+    sqlite-db-connection new-db-connection ;
index eb8c48e3369192f0f834c55dc3bdff4cd155ec29..fd0e6ade743668ae1d1d870dd154d5c3186ec78b 100644 (file)
@@ -6,11 +6,15 @@ IN: db2.transactions
 SYMBOL: in-transaction
 
 HOOK: begin-transaction db-connection ( -- )
+
 HOOK: commit-transaction db-connection ( -- )
+
 HOOK: rollback-transaction db-connection ( -- )
 
 M: db-connection begin-transaction ( -- ) "BEGIN" sql-command ;
+
 M: db-connection commit-transaction ( -- ) "COMMIT" sql-command ;
+
 M: db-connection rollback-transaction ( -- ) "ROLLBACK" sql-command ;
 
 : in-transaction? ( -- ? ) in-transaction get ;