[PATCH] Fix _quote to accept subclasses of 'str' and 'long'
"Pinchart, Laurent" <[email protected]> Fri, 20 Jun 2003 15:00:11 +0200
| Newsgroups | gmane.comp.python.db.pypgsql.user |
|---|---|
| Message-ID | <[email protected]> |
Oops, sorry, forgot to attach the patch. Hi, Here's a patch that fixes a problem in _quote for instances of a subclass of 'str'. pyPgSQL quotes values depending on their type, and uses type() to check the value type. Because of that, instances of a subclass of 'str' are not processed by PgQuoteString like they should. I noticed the problem because util.FieldStorage in mod_python returns instances of a class called 'StringField', which is a subclass of 'str'. The patch also contains a fix for Connection.unlink that hadn't been commited from my last patch. As I received no negative comment about it, I assume that it had been forgotten. Please comment if something is wrong. Laurent Pinchart
PgSQL.py-CVS1.33.diff
(application/octet-stream, 794 B)
--- PgSQL.py 2003-06-20 14:34:59.000000000 +0200
+++ PgSQL.py 2003-06-20 14:39:16.000000000 +0200
@@ -2242,9 +2242,9 @@
return "'%s'" % value
elif type(value) is DateTimeDeltaType:
return "'%s'" % dateTimeDelta2Interval(value)
- elif type(value) is StringType:
+ elif isinstance(value, StringType):
return PgQuoteString(value)
- elif type(value) is LongType:
+ elif isinstance(value, LongType):
return str(value)
else:
return repr(value)
@@ -2592,7 +2592,7 @@
raise InterfaceError, \
"Unlink of large object failed - Connection is not open."
- if self.version.post70 or not self.inTransaction:
+ if not self.version.post70 and self.inTransaction:
raise NotSupportedError, \
"unlink of a PostgreSQL Large Object in a transaction"