]> gitweb.factorcode.org Git - factor.git/commitdiff
db, db.sqlite: If we are in a transaction, don't start another transaction. Add a...
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 30 Mar 2013 00:29:25 +0000 (17:29 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 30 Mar 2013 00:33:54 +0000 (17:33 -0700)
basis/db/db.factor
basis/db/sqlite/sqlite-tests.factor

index 3c924e469888bb8c3067859bfeeffa95fce5c88d..f5d73b917b1e35cf0148aa81cf7c937011970fa3 100644 (file)
@@ -146,7 +146,11 @@ M: db-connection rollback-transaction ( -- ) "ROLLBACK" sql-command ;
 : in-transaction? ( -- ? ) in-transaction get ;
 
 : with-transaction ( quot -- )
-    t in-transaction [
-        begin-transaction
-        [ ] [ rollback-transaction ] cleanup commit-transaction
-    ] with-variable ; inline
+    in-transaction? [
+        call
+    ] [
+        t in-transaction [
+            begin-transaction
+            [ ] [ rollback-transaction ] cleanup commit-transaction
+        ] with-variable
+    ] if ; inline
index e5680a1d0a47ffd84b25f7d8ee56e51466fc478d..b389847fc946c0edfd454a9c62f3af4b6982218c 100644 (file)
@@ -162,3 +162,13 @@ watch "WATCH" {
         user>> f user boa select-tuple
     ] with-db
 ] unit-test
+
+{ } [
+    test.db [ [
+            user ensure-table [
+                "mew" "foo" user boa insert-tuple
+                "denny" "kitty" user boa insert-tuple
+            ] with-transaction
+        ] with-transaction
+    ] with-db
+] unit-test