| Message: 67441 |
 |
BY: Andrew R Jackson (arjackson) DATE: 2009-04-02 22:11 SUBJECT: RE: Quoting and the Postgres DBD
Looking at a pre-reorg version of the DBI (which I have working elsewhere for a long time), and looking at the commented out quote() method for the current mysql-dbd [in database.rb], perhaps this might be of interest to those wanting the DBI interface working again as documented:
def quote(value)
case value
when String
value = value.gsub(/'/, "''") # ' (for ruby-mode)
"'#{value}'"
when DBI::Binary
value = quote(value.to_s)
when NilClass
"NULL"
when TrueClass
"'1'"
when FalseClass
"'0'"
when Array
value.collect { |v| quote(v) }.join(", ")
when DBI::Date, DBI::Time, DBI::Timestamp, ::Date
"'#{value.to_s}'"
when ::Time
"'#{value.rfc2822}'"
else
value.to_s
end
end
Of course, adjustments for your specific DBD may be needed, and you realize if there were problems with this old quoting...well, you'll be happy about the consistency...
| |