Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread
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...


Thread View

Thread Author Date
Quoting and the Postgres DBDDavid Evans2009-03-26 11:07
      RE: Quoting and the Postgres DBDErik Hollensbe2009-03-26 16:21
            RE: Quoting and the Postgres DBDMike Pomraning2009-03-27 03:24
      RE: Quoting and the Postgres DBDAndrew R Jackson2009-04-02 21:18
            RE: Quoting and the Postgres DBDAndrew R Jackson2009-04-02 22:11

Post a followup to this message