# SQLite in-memory

**URL:** <https://www.ruby-forum.com/t/sqlite-in-memory/74478>\
**Category:** Rails\
**Created:** [December 23, 2005, 6:38pm UTC](https://www.ruby-forum.com/t/sqlite-in-memory/74478 "2005-12-23T18:38:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [December 23, 2005, 6:38pm UTC](https://www.ruby-forum.com/t/sqlite-in-memory/74478/1 "2005-12-23T18:38:25Z")

</div>

I left “:memory:” in database.yml for testing and the most simple  
tests in the Agile book do not work (see trace below for test\_truth).  
Since that’s what comes with the distributed database.yml I suppose  
it’s me doing something wrong.

Did someone get SQLite “:memory:” working? How does it grab the schema?

– fxn

% rake test\_units  
(in /Users/fxn/study/rails/depot)  
/usr/local/bin/ruby -Ilib:test “/usr/local/lib/ruby/gems/1.8/gems/  
rake-0.6.2/lib/rake/rake\_test\_loader.rb” “test/unit/  
line\_item\_test.rb” “test/unit/order\_test.rb” “test/unit/  
product\_test.rb” “test/unit/user\_test.rb”  
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/  
rake\_test\_loader  
Started  
FFE/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/  
errors.rb:94:in `check': cannot rollback - no transaction is active (SQLite3::SQLException) from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/ lib/sqlite3/resultset.rb:76:in`check’  
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/  
lib/sqlite3/resultset.rb:68:in `commence' from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/ lib/sqlite3/resultset.rb:61:in`initialize’  
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/  
lib/sqlite3/statement.rb:158:in `execute' from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/ lib/sqlite3/database.rb:211:in`execute’  
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/  
lib/sqlite3/database.rb:186:in `prepare' from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/ lib/sqlite3/database.rb:210:in`execute’  
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/  
lib/sqlite3/database.rb:620:in `rollback' ... 11 levels... from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:200:in`run’  
from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:13:in  
`run’  
from /usr/local/lib/ruby/1.8/test/unit.rb:285  
from /usr/local/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/  
rake\_test\_loader.rb:5

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [December 24, 2005, 11:32am UTC](https://www.ruby-forum.com/t/sqlite-in-memory/74478/2 "2005-12-24T11:32:28Z")

</div>

On 23/12/05, Xavier N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I left “:memory:” in database.yml for testing and the most simple  
> tests in the Agile book do not work (see trace below for test\_truth).  
> Since that’s what comes with the distributed database.yml I suppose  
> it’s me doing something wrong.

Lazy guess, but have you tried toggling the

self.use\_transactional\_fixtures

setting in

test/test\_helper.rb

?

–  
Rasputin :: Jack of All Trades - Master of Nuns  
[http://number9.hellooperator.net/](http://number9.hellooperator.net/)

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [December 24, 2005, 12:20pm UTC](https://www.ruby-forum.com/t/sqlite-in-memory/74478/3 "2005-12-24T12:20:34Z")

</div>

On Dec 24, 2005, at 11:30, Dick D. wrote:

> setting in
> 
> test/test\_helper.rb
> 
> ?

If we set that to false (so actual insertions and deletions are  
done), the test tries to delete the products table and fails there,  
which seems to suggest that the schema was not created. See output  
below.

The piece I think I am missing is how to create the schema in that  
database. In files one does it explicitly, but since that database is  
created by the testing framework in memory I don’t now how it figures  
the schema out (I would expect it to run the equivalent of “rake  
clone\_structure\_to\_test” behind the scenes), or whether some hook is  
provided I don’t know about.

If I was right, do you know by any chance what should I do? This in-  
memory database for testing looks really handy.

– fxn

% ruby test/unit/product\_test.rb  
Loaded suite test/unit/product\_test  
Started  
EE  
Finished in 0.079896 seconds.

1. Error:  
test\_read\_with\_fixture\_variable\_as\_instance(ProductTest):  
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table:  
products: DELETE FROM products WHERE 1=1  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/connection\_adapters/abstract\_adapter.rb:88:in `log' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/connection_adapters/sqlite_adapter.rb:133:in`execute’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/connection\_adapters/sqlite\_adapter.rb:143:in `delete' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:279:in`delete\_existing\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/fixtures.rb:252:in `create_fixtures' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:252:in`create\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/connection\_adapters/abstract/database\_statements.rb:  
51:in `transaction' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:251:in`create\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/base.rb:831:in `silence' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:244:in`create\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/fixtures.rb:540:in `load_fixtures' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:496:in`setup\_with\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/fixtures.rb:522:in `setup’

2. Error:  
test\_read\_with\_hash(ProductTest):  
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table:  
products: DELETE FROM products WHERE 1=1  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/connection\_adapters/abstract\_adapter.rb:88:in `log' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/connection_adapters/sqlite_adapter.rb:133:in`execute’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/connection\_adapters/sqlite\_adapter.rb:143:in `delete' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:279:in`delete\_existing\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/fixtures.rb:252:in `create_fixtures' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:252:in`create\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/connection\_adapters/abstract/database\_statements.rb:  
51:in `transaction' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:251:in`create\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/base.rb:831:in `silence' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:244:in`create\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/fixtures.rb:540:in `load_fixtures' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ active_record/fixtures.rb:496:in`setup\_with\_fixtures’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/  
active\_record/fixtures.rb:522:in `setup’

2 tests, 0 assertions, 0 failures, 2 errors
