Yes, Aaron. I stated that before. And when you instantiate this object is in 
the only place where connection is opened. There is no open method to use after 
a close.

To make it clear: with MySQL adapter this works, it only happens with the 
SQLite adapter.

Let me create a dummy example and you'll get the problem instantly, but to 
recap:

- I want to separate the connection used to run migrations and the connection 
used for the runtime.
- I override connection method on my migrations and inside I call 
establish_connection.
- I am using the sqlite3 gem and adapter locally.

I am going to dig even more, but my guess is that the sqlite3 adapter instance 
is reused by the pool, getting to a 'closed database problem' after calling to 
establish_connection.


Best regards,
Rafael Fernández López

El 21/04/2012, a las 00:35, Aaron Patterson <[email protected]> escribió:

> On Fri, Apr 20, 2012 at 06:11:02PM +0200, Rafael Fernández López wrote:
>> Hello all,
>> 
>> Ok, so here is the report. Studying the source code I got to the interesting 
>> part:
>> 
>> connection_specification.rb (in activerecord/connection_adapters/abstract)
>> 
>> def self.establish_connection(spec = ENV["DATABASE_URL"])
>>  …
>>  remove_connection
>>  connection_handler.establish_connection name, spec
>> end
>> 
>> And here is where all the work comes… I tracked all this process, and the 
>> "problem" resides in that sqlite3 gem as well as the sqlite_adapter.rb (in 
>> active_record/connection_adapters) does not implement the "connect" method.
>> 
>> The sqlite gem only performs a sqlite3_open call in the initialize method. 
>> There is a close method, but there isn't an open method. So the dummy one is 
>> called that does nothing, and you end with only the new closed connection. 
>> And a nice point to remark is also that this only happens when we have DDL 
>> transactions. With DDL transactions disabled (as in my previous email) the 
>> connection is recreated instead of reopened, and for this reason this works 
>> out of the box.
> 
> I don't understand this at all.  Simply instantiating a SQLite database
> object will give you an open connection:
> 
>  db = SQLite3::Database.new ':memory:' # => it's open now
> 
> 
> -- 
> Aaron Patterson
> http://tenderlovemaking.com/

-- 
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 [email protected].
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.

Reply via email to