more work on db2

db4
Doug Coleman 2009-04-11 20:21:04 -05:00
parent badbd014be
commit ee45c8ff20
5 changed files with 28 additions and 9 deletions

View 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

View 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

View 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 ;

View 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 ;

View 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 ;