1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #13640 from maginatics/fix_sqlite3_ensure_master

SQLite3: Always close statements.

Conflicts:
	activerecord/CHANGELOG.md
This commit is contained in:
Rafael Mendonça França 2014-05-01 14:10:04 -03:00
commit 372e28ce22
3 changed files with 27 additions and 3 deletions

View file

@ -1,3 +1,9 @@
* Ensure SQLite3 statements are closed on errors.
Fixes: #13631
*Timur Alperovich*
* Give ActiveRecord::PredicateBuilder private methods the privacy they deserve
*Hector Satre*

View file

@ -296,9 +296,12 @@ module ActiveRecord
# Don't cache statements if they are not prepared
if without_prepared_statement?(binds)
stmt = @connection.prepare(sql)
cols = stmt.columns
records = stmt.to_a
stmt.close
begin
cols = stmt.columns
records = stmt.to_a
ensure
stmt.close
end
stmt = records
else
cache = @statements[sql] ||= {

View file

@ -416,6 +416,21 @@ module ActiveRecord
assert @conn.respond_to?(:disable_extension)
end
def test_statement_closed
db = SQLite3::Database.new(ActiveRecord::Base.
configurations['arunit']['database'])
statement = SQLite3::Statement.new(db,
'CREATE TABLE statement_test (number integer not null)')
statement.stubs(:step).raises(SQLite3::BusyException, 'busy')
statement.stubs(:columns).once.returns([])
statement.expects(:close).once
SQLite3::Statement.stubs(:new).returns(statement)
assert_raises ActiveRecord::StatementInvalid do
@conn.exec_query 'select * from statement_test'
end
end
private
def assert_logged logs