From bfa6bfc24a0034ae599861a6e8655df024973eed Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson <david@loudthinking.com> Date: Mon, 14 Mar 2005 23:48:39 +0000 Subject: Fixed that SQLite3 exceptions are caught and reported properly #823 [yerejm] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@909 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ .../lib/active_record/connection_adapters/abstract_adapter.rb | 4 ++-- activerecord/test/connections/native_sqlite/connection.rb | 2 +- activerecord/test/connections/native_sqlite3/connection.rb | 2 +- activerecord/test/finder_test.rb | 4 ++++ 5 files changed, 10 insertions(+), 4 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index ec1fd93ff5..7f1a1fcca4 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that SQLite3 exceptions are caught and reported properly #823 [yerejm] + * Added that all types of after_find/after_initialized callbacks are triggered if the explicit implementation is present, not only the explicit implementation itself * Fixed that symbols can be used on attribute assignment, like page.emails.create(:subject => data.subject, :body => data.body) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index cf7f07ba26..ac58b60e8d 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -405,7 +405,7 @@ module ActiveRecord log_info(sql, name, 0) nil end - rescue => e + rescue Exception => e log_info("#{e.message}: #{sql}", name, 0) raise ActiveRecord::StatementInvalid, "#{e.message}: #{sql}" end @@ -453,4 +453,4 @@ module ActiveRecord end end end -end \ No newline at end of file +end diff --git a/activerecord/test/connections/native_sqlite/connection.rb b/activerecord/test/connections/native_sqlite/connection.rb index e702006bc2..b686c7705b 100644 --- a/activerecord/test/connections/native_sqlite/connection.rb +++ b/activerecord/test/connections/native_sqlite/connection.rb @@ -13,7 +13,7 @@ sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite" def make_connection(clazz, db_file, db_definitions_file) unless File.exist?(db_file) puts "SQLite database not found at #{db_file}. Rebuilding it." - sqlite_command = "sqlite #{db_file} 'create table a (a integer); drop table a;'" + sqlite_command = %Q{sqlite #{db_file} "create table a (a integer); drop table a;"} puts "Executing '#{sqlite_command}'" raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command) clazz.establish_connection( diff --git a/activerecord/test/connections/native_sqlite3/connection.rb b/activerecord/test/connections/native_sqlite3/connection.rb index 640a2b97f5..07856cc677 100644 --- a/activerecord/test/connections/native_sqlite3/connection.rb +++ b/activerecord/test/connections/native_sqlite3/connection.rb @@ -13,7 +13,7 @@ sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3" def make_connection(clazz, db_file, db_definitions_file) unless File.exist?(db_file) puts "SQLite3 database not found at #{db_file}. Rebuilding it." - sqlite_command = "sqlite3 #{db_file} 'create table a (a integer); drop table a;'" + sqlite_command = %Q{sqlite3 #{db_file} "create table a (a integer); drop table a;"} puts "Executing '#{sqlite_command}'" raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command) clazz.establish_connection( diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 30b0b78313..a5eaca039e 100755 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -233,6 +233,10 @@ class FinderTest < Test::Unit::TestCase assert_equal "Mary", topics[0].author_name end + def test_find_with_bad_sql + assert_raises(ActiveRecord::StatementInvalid) { Topic.find_by_sql "select 1 from badtable" } + end + protected def bind(statement, *vars) if vars.first.is_a?(Hash) -- cgit v1.2.3