This project is archived and is in readonly mode.
SQLiteAdapter fails with a dark message when creating columns when inside a transaction
Reported by Gunnar Wolf | May 14th, 2008 @ 06:55 PM
While running some tests which require modifying some fields in a DB table, I ran across a problem that made me lose quite some time. The error I got when running the test (under SQLite3) was:
ActiveRecord::StatementInvalid: SQLite3::SQLException: SQL logic error or missing database: VACUUM
Now, digging into ConnectionAdapters::SQLiteAdapter, I found:
def add_column(table_name, column_name, type, options = {}) #:nodoc:
super(table_name, column_name, type, options)
- See last paragraph on http://www.sqlite.org/lang_alter...
execute "VACUUM"
end
Now... Refering to its own documentation, SQLite will fail on vacuums when there is an active transaction (http://www.sqlite.org/lang_vacuu...)... So my tests fail miserably.
I would suggest either of the attached patches.
First version: Try to create the requested column; if it was called in mid-transaction, the DB won't be readable with older versions of MySQL, but it will succeed:
The second possibility is just to disallow adding columns while in a transaction:
Any of them will be better than just leaving the user scratching his head to understand where the error lies :)
Comments and changes to this ticket
-
Gunnar Wolf May 14th, 2008 @ 06:54 PM
UGH... This got formatted as hell. I'm uploading both versions of the patch.
Here goes the first version: Try to make it work, just leaving out the vacuum
-
Pratik May 19th, 2008 @ 11:12 AM
- State changed from new to incomplete
- Assigned user set to Pratik
Can you please add a test case verifying expected exception is raised for sqlite adapter ?
Thanks.
-
Gunnar Wolf May 19th, 2008 @ 05:33 PM
Here it is - I'm doing the test for the second case I mentioned (raising a StatementInvalid when adding a column inside a transaction).
Stylistically it might be quite un-railish - But it does work as expected.
-
Repository May 20th, 2008 @ 11:14 AM
- State changed from incomplete to resolved
(from [089251581137b041828a7e6dcbf75ecbef55b4a3]) Ensure add_column gives valid error for sqlite. [Gunnar Wolf, Pratik] [#197 state:resolved]
SQLite#add_column executes "VACUUM", which fails if inside a live transaction. This patch
ensures a valid exception is raised if add_column is executed within a live transaction for
sqlite adapter.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>