diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-02 12:45:53 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-02 12:45:53 +0000 |
commit | 93221685f131ea689d458bcd78f638fb3d6dfc90 (patch) | |
tree | e4384da8052509cb3687ae0724e8370dd9065ab9 /activerecord/lib/active_record | |
parent | 6bd672eb0d50fcf3437d7fa244245397747bf7a7 (diff) | |
download | rails-93221685f131ea689d458bcd78f638fb3d6dfc90.tar.gz rails-93221685f131ea689d458bcd78f638fb3d6dfc90.tar.bz2 rails-93221685f131ea689d458bcd78f638fb3d6dfc90.zip |
Restored bind arity checking #412 [bitsweat]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@306 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e0e7c37d73..63810d3c41 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -681,18 +681,13 @@ module ActiveRecord #:nodoc: alias_method :sanitize_conditions, :sanitize_sql def replace_bind_variables(statement, values) - expected_number_of_variables = statement.count('?') - provided_number_of_variables = values.size - - unless expected_number_of_variables == provided_number_of_variables - raise PreparedStatementInvalid, "wrong number of bind variables (#{provided_number_of_variables} for #{expected_number_of_variables}) in: #{statement}" - end - + raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size) bound = values.dup statement.gsub('?') { connection.quote(bound.shift) } end def replace_named_bind_variables(statement, bind_vars) + raise_if_bind_arity_mismatch(statement, statement.scan(/:(\w+)/).uniq.size, bind_vars.size) statement.gsub(/:(\w+)/) do match = $1.to_sym if bind_vars.has_key?(match) @@ -703,6 +698,12 @@ module ActiveRecord #:nodoc: end end + def raise_if_bind_arity_mismatch(statement, expected, provided) + unless expected == provided + raise PreparedStatementInvalid, "wrong number of bind variables (#{provided} for #{expected}) in: #{statement}" + end + end + def extract_options_from_args!(args) if args.last.is_a?(Hash) then args.pop else {} end end |