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@3997 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 f340df79
*SVN*
* 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]
* Don't classify the has_one class when eager loading, it is already singular. Add tests. (closes #4117) [jonathan@bluewire.net.nz]
* Quit ignoring default :include options in has_many :through calls [Mark James]
......
......@@ -135,6 +135,13 @@ def quote_column_name(name) #:nodoc:
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
end
def update(sql, name = nil) #:nodoc:
......@@ -341,13 +348,18 @@ class SQLite2Adapter < SQLiteAdapter # :nodoc:
#
# SELECT COUNT(ArtistID) FROM (SELECT DISTINCT ArtistID FROM CDs);
def execute(sql, name = nil) #:nodoc:
super(rewrite_count_distinct_queries(sql), name)
end
def rewrite_count_distinct_queries(sql)
if sql =~ /count\(distinct ([^\)]+)\)( AS \w+)? (.*)/i
distinct_column = $1
distinct_query = $3
column_name = distinct_column.split('.').last
sql = "SELECT COUNT(#{column_name}) FROM (SELECT DISTINCT #{distinct_column} #{distinct_query})"
"SELECT COUNT(#{column_name}) FROM (SELECT DISTINCT #{distinct_column} #{distinct_query})"
else
sql
end
log(sql, name) { @connection.execute(sql) }
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册