Skip to content
Browse files

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
  • Loading branch information...
1 parent df62dea commit 6d627b6725beca23eb07ee7c924363eb6249cef0 @dhh dhh committed
Showing with 15 additions and 11 deletions.
  1. +15 −11 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
View
26 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -134,14 +134,7 @@ def quote_column_name(name) #:nodoc:
# 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 @@ def select_one(sql, name = nil) #:nodoc:
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 @@ def copy_table_contents(from, to, columns, rename = {}) #:nodoc:
@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:

0 comments on commit 6d627b6

Please sign in to comment.
Something went wrong with that request. Please try again.