On Sep 26, 2007, at 4:53 PM, Michael Koziarski wrote:

>
> What do you mean by 'rolling back' model creation.  The transaction
> should definitely be aborted.  The database should be left as it was
> before.   If not, you've found a bug for which test cases would be
> greatly appreciated ;)


hey koz-

note that i *am* abusing the api a *little*  (see commented line)

here are two samples:


======================================================================== 
=======
cfp:~ > cat sqlite.sh
cd

rm -rf transactions

rails transactions --database=sqlite3 > /dev/null

cd transactions

mkdir ./db/migrate/

cat > ./db/migrate/001_foos.rb <<EOS
   class Foos < ActiveRecord::Migration
     def self.up
       create_table :foos do |t|
         t.column :bar, :text
       end
     end

     def self.down
       drop_table :foos
     end
   end
EOS

rake db:migrate >/dev/null

./script/generate model foo >/dev/null

cat > a.rb <<-ruby
   Foo.delete_all

   begin
     #ActiveRecord::Base.transaction do
     ActiveRecord::Base.connection.transaction do
       p :a => Foo.count
       Foo.create!
       p :b => Foo.count
       raise
     end
   rescue Exception => e
     m, c, b = e.message, e.class, [e.backtrace].join("\n")
     STDERR.puts "#{ m } (#{ c })\n#{ b }"
   end

   p :c => Foo.count
ruby

./script/runner a.rb

cd


======================================================================== 
=======
cfp:~ > ./sqlite.sh
{:a=>0}
cannot start a transaction within a transaction (SQLite3::SQLException)
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
errors.rb:94:in `check'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
resultset.rb:76:in `check'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
resultset.rb:68:in `commence'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
resultset.rb:61:in `initialize'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
statement.rb:163:in `new'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
statement.rb:163:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
database.rb:212:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
database.rb:187:in `prepare'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
database.rb:211:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ 
database.rb:588:in `transaction'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/connection_adapters/sqlite_adapter.rb:183:in  
`begin_db_transaction'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/connection_adapters/sqlite_adapter.rb:346:in  
`catch_schema_changes'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/connection_adapters/sqlite_adapter.rb:183:in  
`begin_db_transaction'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/connection_adapters/abstract/database_statements.rb: 
56:in `transaction'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/transactions.rb:95:in `transaction'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/transactions.rb:121:in `transaction'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/transactions.rb:133:in `save!'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/validations.rb:727:in `create!'
(eval):7
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/connection_adapters/abstract/database_statements.rb: 
59:in `transaction'
(eval):5
/opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in  
`eval'
/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/runner.rb:45
/opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in  
`gem_original_require'
/opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in  
`require'
./script/runner:3
{:c=>0}


======================================================================== 
=======
cfp:~ > cat postgresql.sh
#! /usr/bin/env bash

cd

rm -rf transactions

rails transactions --database=postgresql > /dev/null

cd transactions

dropdb transactions > /dev/null 2>&1
createdb transactions > /dev/null 2>&1

cat > ./config/database.yml <<EOS
development:
   adapter: postgresql
   database: transactions
   host: localhost
   encoding: UTF8
EOS

mkdir ./db/migrate/

cat > ./db/migrate/001_foos.rb <<EOS
   class Foos < ActiveRecord::Migration
     def self.up
       create_table :foos do |t|
         t.column :bar, :text
       end
     end

     def self.down
       drop_table :foos
     end
   end
EOS

rake db:migrate >/dev/null

./script/generate model foo >/dev/null

cat > a.rb <<-ruby
   Foo.delete_all

   begin
     #ActiveRecord::Base.transaction do
     ActiveRecord::Base.connection.transaction do
       p :a => Foo.count
       Foo.create!
       p :b => Foo.count
       raise
     end
   rescue Exception => e
     m, c, b = e.message, e.class, [e.backtrace].join("\n")
     STDERR.puts "#{ m } (#{ c })\n#{ b }"
   end

   p :c => Foo.count
ruby

./script/runner a.rb

cd


======================================================================== 
=======
cfp:~ > ./postgresql.sh
NOTICE:  CREATE TABLE will create implicit sequence "foos_id_seq" for  
serial column "foos.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index  
"foos_pkey" for table "foos"
{:a=>0}
WARNING:  there is already a transaction in progress
{:b=>1}
WARNING:  there is no transaction in progress
(RuntimeError)
(eval):9
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
active_record/connection_adapters/abstract/database_statements.rb: 
59:in `transaction'
(eval):5
/opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in  
`eval'
/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/runner.rb:45
/opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in  
`gem_original_require'
/opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in  
`require'
./script/runner:3
{:c=>1}




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: sqlite.sh
Description: Binary data


Attachment: postgresql.sh
Description: Binary data


kind regards.


a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama



Reply via email to