ActiveRecord::Rollback Config Help

K

kels0n

I'm struggling with why ActiveRecord isn't rolling back my
transactions. I've ran the same code at my home machine and it works
but on my work machine it doesn't and I'm hoping will see the
glaringly obvious configuration problem that can't see. I can connect
to the database and perform actions just fine.

I'm running Ruby on Windows XP and connecting to SQL Server 2005.
ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
gem list --local

*** LOCAL GEMS ***

actionmailer (2.3.5, 1.3.6)
actionpack (2.3.5, 1.13.6)
actionwebservice (1.2.6)
activerecord (2.3.5, 1.15.6)
activerecord-sqlserver-adapter (2.3)
activeresource (2.3.5)
activesupport (2.3.5, 1.4.4)
autotest (4.2.3)
dbd-odbc (0.2.4)
dbi (0.4.1)
deprecated (2.0.1)
echoe (4.1)
ezcrypto (0.7.2)
fxri (0.3.7, 0.3.6)
fxruby (1.6.16)
gemcutter (0.3.0)
hpricot (0.6.164)
json_pure (1.2.0)
log4r (1.0.5)
mocha (0.9.8)
ptools (1.1.6)
rack (1.0.1)
rails (2.3.5, 1.2.6)
rake (0.8.7, 0.8.1)
ruby-opengl (0.60.0)
rubyforge (2.0.3)
rubygems-update (1.3.5)
rubyzip (0.9.1)
test-unit (2.0.1)
thoughtbot-shoulda (2.10.2)
win32-api (1.2.1, 1.2.0)
win32-clipboard (0.4.4)
win32-dir (0.3.2)
win32-eventlog (0.5.0)
win32-file (0.5.5)
win32-file-stat (1.3.1)
win32-process (0.5.9)
win32-sapi (0.1.4)
win32-sound (0.4.1)
windows-api (0.2.4)
windows-pr (0.9.3)

The script I'm using to test transactions is:

require 'active_record'

class TestRollback < ActiveRecord::Base
end

ActiveRecord::Base.establish_connection(
:adapter => 'sqlserver',
:username => 'user',
:password => 'pass',
:database => 'testdb',
:host => 'localhost'
)

TestRollback.transaction do
TestRollback.create:)name => 'Test')
raise ActiveRecord::Rollback
end

TestRollback.find:)all) # returns [#<TestRollback name: "Test">]

The only difference between this configuration and my one at home is I
don't have version 1.15.6 of the activerecord gem installed on my home
machine. However, this script needs to use that version of
activerecord because of some legacy code that I inherited and haven't
had a chance to rewrite. I'm hoping there's a way around this without
having to rewrite the code.

Any ideas?
 
R

Robert Klemme

2010/1/28 kels0n said:
class TestRollback < ActiveRecord::Base
end

ActiveRecord::Base.establish_connection(
=A0:adapter =3D> 'sqlserver',
=A0:username =3D> 'user',
=A0:password =3D> 'pass',
=A0:database =3D> 'testdb',
=A0:host =3D> 'localhost'
)

TestRollback.transaction do
=A0TestRollback.create:)name =3D> 'Test')
=A0raise ActiveRecord::Rollback
end

TestRollback.find:)all) =A0# returns [#<TestRollback name: "Test">]

The only difference between this configuration and my one at home is I
don't have version 1.15.6 of the activerecord gem installed on my home
machine. =A0However, this script needs to use that version of
activerecord because of some legacy code that I inherited and haven't
had a chance to rewrite. =A0I'm hoping there's a way around this without
having to rewrite the code.

Any ideas?

I can't help you with AR but just making sure we exclude the easy
mistakes which still happen all the time: you have verified that the
record in question is not in the table before the TX starts, did you?

Kind regards

robert


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top