Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord::Base#sanitize_sql_hash_for_conditions & #sanitize_sql_hash_for_assignment should pass column to #quote_bound_value

#2554

Attached is a patch that tweaks ActiveRecord::Base#sanitize_sql_hash_for_conditions and ActiveRecord::Base#sanitize_sql_hash_for_assignment to pass the column object for attributes, so adapters can better handle quoting their values.

For example, the SQL Server ActiveRecord adapter needs to prefix N to Unicode literals.

It's passing all MySQL tests.

Reported by Erik Bryn · April 24th, 2009 @ 03:02 AM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Ken Collins
    Ken Collins

    I just tried this patch on current master and it does pass all the tests in all three DBs. Can their be tests added for this? It might get acceptance quicker if it did? For instance test that the postgresql quoting for say the bit hexadecimal type?

    
            elsif value.kind_of?(String) && column && column.sql_type =~ /^bit/
              case value
                when /^[01]*$/
                  "B'#{value}'" # Bit-string notation
                when /^[0-9A-F]*$/i
                  "X'#{value}'" # Hexadecimal notation
    

    If there is no matching schema in the postgresql_specific_schema.rb file, I'm sure one can be added. What do you think?

    May 12th, 2009 @ 02:52 PM

  2. Bruce Burdick
    Bruce Burdick

    This is a really bad design that will result in data corruption every time it is passed a string representing a hexadecimal number that is strictly composed of zeros and ones. It is not possible to determine whether such a string represents a binary or hexadecimal number by scanning its contents. Ruby itself imposes prefix tags to make this distinction: e.g. 0b1010 vs. 0x1010. No ActiveRecord DB driver should pretend to infer the base of an untagged string of ones and zeros.

    The solution must either:
    * avoid using bitstring column types altogether (not preferred) * pick either binary or hexadecimal, reject the other, and fix the driver code * reject untagged strings and fix the driver code

    September 26th, 2009 @ 11:55 PM

  3. Bruce Burdick
  4. Bruce Burdick
  5. Bruce Burdick
    Bruce Burdick

    To be clear: I'm referring to the code block posted by Ken Collins, not to Erik Bryn's diff (which I have not read).

    September 27th, 2009 @ 12:13 AM

  6. Ken Collins
    Ken Collins

    Man this is old and I have no idea what I was even talking about. I'll just bow out now :)

    October 2nd, 2009 @ 04:07 PM

  7. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  8. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:02 PM

  9. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:02 PM