Update of /cvsroot/ruby-dbi/src/lib/dbd_pg
In directory usw-pr-cvs1:/tmp/cvs-serv20317
Modified Files:
Pg.rb
Log Message:
Use PostgreSQL specific quoting function (PGconn.quote) instead of default if available.
Use PGconn.escape_bytea instead of own __escape_bytea function if available.
Index: Pg.rb
===================================================================
RCS file: /cvsroot/ruby-dbi/src/lib/dbd_pg/Pg.rb,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Pg.rb 26 Sep 2002 13:40:32 -0000 1.27
+++ Pg.rb 22 Oct 2002 14:00:16 -0000 1.28
@@ -282,16 +282,32 @@
@coerce.coerce(converter, obj)
end
+ if PGconn.respond_to?(:quote)
+
+ def quote(value)
+ PGconn.quote(value) {|value|
+ case value
+ when DBI::Date, DBI::Time, DBI::Timestamp, ::Date, ::Time
+ "'#{value.to_s}'"
+ else
+ value.to_s
+ end
+ }
+ end
+
+ else
+
def quote(value)
- # TODO: new quote function of Pg driver
case value
when String
- "'#{ value.gsub(/\\/){ '\\\\' }.gsub(/'/){ '\\\'' } }'"
+ "'#{ value.gsub(/\\/){ '\\\\' }.gsub(/'/){ '\\\'' } }'"
else
- super
+ super
end
end
-
+
+ end
+
private # ----------------------------------------------------
@@ -369,7 +385,15 @@
raise DBI::DatabaseError.new(err.message)
end
- #
+ if PGconn.respond_to?(:escape_bytea)
+
+ def __encode_bytea(str)
+ PGconn.escape_bytea(str)
+ end
+
+ else
+
+ ##
# encodes a string as bytea value.
#
# for encoding rules see:
@@ -384,6 +408,8 @@
}
a.join("\\\\") # \ => \\
end
+
+ end
end # Database
|