Fixed that schema changes while the database was open would break any connections to a SQLite database (now we reconnect if that error is throw) [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3998 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson
2006-03-20 06:09:57 +00:00
parent df62dea1ff
commit 6d627b6725

View File

@@ -134,14 +134,7 @@ module ActiveRecord
# DATABASE STATEMENTS ======================================
def execute(sql, name = nil) #:nodoc:
log(sql, name) { @connection.execute(sql) }
rescue ActiveRecord::StatementInvalid => exception
if exception.message =~ /database schema has changed/
reconnect!
retry
else
raise
end
catch_schema_changes { log(sql, name) { @connection.execute(sql) } }
end
def update(sql, name = nil) #:nodoc:
@@ -179,15 +172,15 @@ module ActiveRecord
def begin_db_transaction #:nodoc:
@connection.transaction
catch_schema_changes { @connection.transaction }
end
def commit_db_transaction #:nodoc:
@connection.commit
catch_schema_changes { @connection.commit }
end
def rollback_db_transaction #:nodoc:
@connection.rollback
catch_schema_changes { @connection.rollback }
end
@@ -337,6 +330,17 @@ module ActiveRecord
@connection.execute sql
end
end
def catch_schema_changes
return yield
rescue ActiveRecord::StatementInvalid => exception
if exception.message =~ /database schema has changed/
reconnect!
retry
else
raise
end
end
end
class SQLite2Adapter < SQLiteAdapter # :nodoc: