diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-20 06:09:57 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-20 06:09:57 +0000 |
commit | 6d627b6725beca23eb07ee7c924363eb6249cef0 (patch) | |
tree | aabd0f06cfae62b7de46ad3a0b1d54ca9f9e8b11 /activerecord/lib/active_record | |
parent | df62dea1ff1461322e54bba7bbbee227a3e32b4e (diff) | |
download | rails-6d627b6725beca23eb07ee7c924363eb6249cef0.tar.gz rails-6d627b6725beca23eb07ee7c924363eb6249cef0.tar.bz2 rails-6d627b6725beca23eb07ee7c924363eb6249cef0.zip |
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
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index ab5c9b822f..8038bc7051 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -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: |