Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Changed update to use prepared statements #9246

Merged
merged 1 commit into from Feb 25, 2013

Conversation

Projects
None yet
3 participants
Contributor

olliwer commented Feb 11, 2013

Arel changes required for the binding can be seen here:
rails/arel@b4fd431
rails/arel@9c514f3

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Feb 11, 2013

...ecord/test/cases/adapters/postgresql/datatype_test.rb
assert @first_bit_string.bit_string = new_bit_string
assert @first_bit_string.bit_string_varying = new_bit_string_varying
assert @first_bit_string.save
assert @first_bit_string.reload
- assert_equal @first_bit_string.bit_string, new_bit_string
- assert_equal @first_bit_string.bit_string, @first_bit_string.bit_string_varying
+ assert_equal new_bit_string, @first_bit_string.bit_string
+ assert_equal new_bit_string_varying, @first_bit_string.bit_string_varying
@carlosantoniodasilva

carlosantoniodasilva Feb 11, 2013

Owner

I think this has already been committed to master in cdd293c, right?

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Feb 11, 2013

activerecord/test/cases/adapter_test.rb
@@ -6,6 +7,19 @@ def setup
@connection = ActiveRecord::Base.connection
end
+ ##
+ # PostgreSQL does not support null bytes in strings
+ unless current_adapter?(:PostgreSQLAdapter)
+ def test_update_prepared_statement
+ b = Book.create(:name => "my \x00 book")
+ b.reload
+ assert_equal "my \x00 book", b.name
+ b.update_attributes(:name => "my other \x00 book")
@carlosantoniodasilva

carlosantoniodasilva Feb 11, 2013

Owner

Please use 1.9 style hash: name: "..." in both places.

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Feb 11, 2013

activerecord/lib/active_record/persistence.rb
if attributes_with_values.empty?
0
else
klass = self.class
- stmt = klass.unscoped.where(klass.arel_table[klass.primary_key].eq(id)).arel.compile_update(attributes_with_values)
- klass.connection.update stmt
+ column_hash = klass.connection.schema_cache.columns_hash klass.table_name
+ db_columns_with_values = attributes_with_values.map { |attr,value|
+ real_column = column_hash[attr.name]
+ [real_column, value]
Contributor

olliwer commented Feb 11, 2013

Rebased commits for simplicity

@tenderlove tenderlove added a commit that referenced this pull request Feb 25, 2013

@tenderlove tenderlove Merge pull request #9246 from Noemj/update_prepared_statements
Changed update to use prepared statements
45321a6

@tenderlove tenderlove merged commit 45321a6 into rails:master Feb 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment