aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-20 06:05:16 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-20 06:05:16 +0000
commitdf62dea1ff1461322e54bba7bbbee227a3e32b4e (patch)
tree906248b2e47a6701517132a202087c3734ad76b8
parentf340df798e62b9c92c2c322d3f56a00eb2523de7 (diff)
downloadrails-df62dea1ff1461322e54bba7bbbee227a3e32b4e.tar.gz
rails-df62dea1ff1461322e54bba7bbbee227a3e32b4e.tar.bz2
rails-df62dea1ff1461322e54bba7bbbee227a3e32b4e.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@3997 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb16
2 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index d34aef9477..7949a1736d 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*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]
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index bc874ee58b..ab5c9b822f 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -135,6 +135,13 @@ module ActiveRecord
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 @@ module ActiveRecord
#
# 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