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
上级 066988d2
*SVN* *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 * 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) * Fixed that symbols can be used on attribute assignment, like page.emails.create(:subject => data.subject, :body => data.body)
......
...@@ -405,7 +405,7 @@ def log(sql, name, connection = nil) ...@@ -405,7 +405,7 @@ def log(sql, name, connection = nil)
log_info(sql, name, 0) log_info(sql, name, 0)
nil nil
end end
rescue => e rescue Exception => e
log_info("#{e.message}: #{sql}", name, 0) log_info("#{e.message}: #{sql}", name, 0)
raise ActiveRecord::StatementInvalid, "#{e.message}: #{sql}" raise ActiveRecord::StatementInvalid, "#{e.message}: #{sql}"
end end
...@@ -453,4 +453,4 @@ def column(name, type, options = {}) ...@@ -453,4 +453,4 @@ def column(name, type, options = {})
end end
end end
end end
end end
\ No newline at end of file
...@@ -13,7 +13,7 @@ class SqliteError < StandardError ...@@ -13,7 +13,7 @@ class SqliteError < StandardError
def make_connection(clazz, db_file, db_definitions_file) def make_connection(clazz, db_file, db_definitions_file)
unless File.exist?(db_file) unless File.exist?(db_file)
puts "SQLite database not found at #{db_file}. Rebuilding it." 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}'" puts "Executing '#{sqlite_command}'"
raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command) raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
clazz.establish_connection( clazz.establish_connection(
......
...@@ -13,7 +13,7 @@ class SqliteError < StandardError ...@@ -13,7 +13,7 @@ class SqliteError < StandardError
def make_connection(clazz, db_file, db_definitions_file) def make_connection(clazz, db_file, db_definitions_file)
unless File.exist?(db_file) unless File.exist?(db_file)
puts "SQLite3 database not found at #{db_file}. Rebuilding it." 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}'" puts "Executing '#{sqlite_command}'"
raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command) raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
clazz.establish_connection( clazz.establish_connection(
......
...@@ -233,6 +233,10 @@ def test_find_all_by_nil_and_not_nil_attributes ...@@ -233,6 +233,10 @@ def test_find_all_by_nil_and_not_nil_attributes
assert_equal "Mary", topics[0].author_name assert_equal "Mary", topics[0].author_name
end end
def test_find_with_bad_sql
assert_raises(ActiveRecord::StatementInvalid) { Topic.find_by_sql "select 1 from badtable" }
end
protected protected
def bind(statement, *vars) def bind(statement, *vars)
if vars.first.is_a?(Hash) if vars.first.is_a?(Hash)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册