Fixed that schema changes while the database was open would break any...

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
上级 df62dea1
...@@ -134,14 +134,7 @@ def quote_column_name(name) #:nodoc: ...@@ -134,14 +134,7 @@ def quote_column_name(name) #:nodoc:
# DATABASE STATEMENTS ====================================== # DATABASE STATEMENTS ======================================
def execute(sql, name = nil) #:nodoc: def execute(sql, name = nil) #:nodoc:
log(sql, name) { @connection.execute(sql) } catch_schema_changes { log(sql, name) { @connection.execute(sql) } }
rescue ActiveRecord::StatementInvalid => exception
if exception.message =~ /database schema has changed/
reconnect!
retry
else
raise
end
end end
def update(sql, name = nil) #:nodoc: def update(sql, name = nil) #:nodoc:
...@@ -179,15 +172,15 @@ def select_one(sql, name = nil) #:nodoc: ...@@ -179,15 +172,15 @@ def select_one(sql, name = nil) #:nodoc:
def begin_db_transaction #:nodoc: def begin_db_transaction #:nodoc:
@connection.transaction catch_schema_changes { @connection.transaction }
end end
def commit_db_transaction #:nodoc: def commit_db_transaction #:nodoc:
@connection.commit catch_schema_changes { @connection.commit }
end end
def rollback_db_transaction #:nodoc: def rollback_db_transaction #:nodoc:
@connection.rollback catch_schema_changes { @connection.rollback }
end end
...@@ -337,6 +330,17 @@ def copy_table_contents(from, to, columns, rename = {}) #:nodoc: ...@@ -337,6 +330,17 @@ def copy_table_contents(from, to, columns, rename = {}) #:nodoc:
@connection.execute sql @connection.execute sql
end end
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 end
class SQLite2Adapter < SQLiteAdapter # :nodoc: class SQLite2Adapter < SQLiteAdapter # :nodoc:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册