Package: libdbd-sqlite3-ruby Version: 0.1.1-1 Severity: wishlist Tags: patch
The current SQLite3 DBD provides no transaction support. I've attached a patch that adds transaction support to the DBD. The new 'AutoCommit' attribute is initialized to true to maintain the previous behavior (where each statement is an atomic transaction). When AutoCommit is set to false/nil, a transaction is begun. Transactions are completed by commit/rollback calls (usually by DBI's transaction method), and are implicitly commited when AutoCommit is set to true again.
diff -uNr libdbi-ruby-0.1.1.orig/lib/dbd/SQLite3.rb libdbi-ruby-0.1.1/lib/dbd/SQLite3.rb --- libdbi-ruby-0.1.1.orig/lib/dbd/SQLite3.rb 2007-01-04 18:40:56.000000000 -0500 +++ libdbi-ruby-0.1.1/lib/dbd/SQLite3.rb 2007-01-04 18:44:10.039245409 -0500 @@ -63,7 +63,7 @@ def initialize(dbname, attr) @db = ::SQLite3::Database.new(dbname) # @db.type_translation = true - @attr = {} + @attr = {'AutoCommit' => true} if attr then attr.each_pair do |key, value| begin @@ -76,6 +76,7 @@ end def disconnect() + @db.rollback if @db.transaction_active? @db.close end @@ -88,11 +89,21 @@ end def commit() - @db.commit + if @db.transaction_active? + @db.commit + @db.transaction + else + raise DBI::ProgrammingError.new("No active transaction.") + end end def rollback() - @db.rollback + if @db.transaction_active? + @db.rollback + @db.transaction + else + raise DBI::ProgrammingError.new("No active transaction.") + end end def tables() @@ -160,6 +171,13 @@ def []=(attr, value) case attr + when 'AutoCommit' + if value + @db.commit if @db.transaction_active? + else + @db.transaction unless @db.transaction_active? + end + @attr[attr] = value when 'auto_vacuum', 'cache_size', 'count_changes', 'default_cache_size', 'encoding', 'full_column_names', 'page_size', 'short_column_names', 'synchronous',