Hi,
I have some difficulties getting transaction to work. I wrote a small test
case using RSpec that I expected to result in a complete rollback of all
data already inserted into the database, but in fact there was no rollback:
prepared_content =
[{:col1=>"string1", :col2=>1, :col3=>1.12},
{:col1=>"string2", :col2=>2, :col3=>2.22},
{:col1=>"string3", :col2=>1, :col3=>1.12},
{:col1=>"string4", :col2=>2, :col3=>2.22},
{:col1=>"string5", :col2=>2, :col3=>:invalid}, # invalid field
{:col1=>"string6", :col2=>1, :col3=>1.12}]
DB = Sequel.connect(adapter: 'mysql',
host: 'localhost',
database:'mydb',
user: 'root',
password:'xxx')
unless DB.table_exists?(:data)
DB.create_table(:data) do
primary_key :id, :allow_null => false
String :col1
Integer :col2
Float :col3
end
end
dataset = DB[:data]
lambda do
DB.transaction do
dataset.insert(prepared_content[0])
dataset.insert(prepared_content[1])
dataset.insert(prepared_content[4]) # will raise an exception
end
end.should raise_exception # OK
DB[:data].all.should == []
# Failure/Error: DB[:data].all.should == []
# expected: []
# got: [{:id=>1, :col1=>"string1", :col2=>1, :col3=>1.12},
# {:id=>2, :col1=>"string2", :col2=>2, :col3=>2.22}]
Did I not use #transaction correctly or does Sequel not support transactions
with MySQL?
Any feedback is highly appreciated!
Stefan
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/8tLo05mDbhYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.