aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/python/pgdb.py
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-03-19 02:47:57 +0000
committerBruce Momjian <bruce@momjian.us>2002-03-19 02:47:57 +0000
commitd3337c6e3f9bca1c98ca8e3de218b0e2a5d2f29d (patch)
tree9a481e72810ce10a666df1c47cfb102373c967be /src/interfaces/python/pgdb.py
parenta7ade2bb6b85def8deb30e44c56e80d38e9b9614 (diff)
downloadpostgresql-d3337c6e3f9bca1c98ca8e3de218b0e2a5d2f29d.tar.gz
postgresql-d3337c6e3f9bca1c98ca8e3de218b0e2a5d2f29d.zip
> I am backing out this patch. Please resubmit with this corrected. Thanks.
> > I am running Python 1.5. Therein lies the problem... :) Since it appears you have the requirement of supporting old python versions, attached is just the pgdb.py part of the patch (with a fix for DateTime handling). It has the same functionality but certainly won't be quite as fast. Given the absence of _PyString_Join in python1.5, it's a pain to get the C variants working for all versions. The pgdb.py patch does leaves the hooks in, should someone wish to do the optimization at a later point. Elliot Lee
Diffstat (limited to 'src/interfaces/python/pgdb.py')
-rw-r--r--src/interfaces/python/pgdb.py60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/interfaces/python/pgdb.py b/src/interfaces/python/pgdb.py
index 85ff7656c69..2772809b4e2 100644
--- a/src/interfaces/python/pgdb.py
+++ b/src/interfaces/python/pgdb.py
@@ -260,32 +260,40 @@ class pgdbCursor:
pass
-def _quote(x):
- if type(x) == types.StringType:
- x = "'" + string.replace(
- string.replace(str(x), '\\', '\\\\'), "'", "''") + "'"
-
- elif type(x) in (types.IntType, types.LongType, types.FloatType):
- pass
- elif x is None:
- x = 'NULL'
- elif hasattr(x, '__pg_repr__'):
- x = x.__pg_repr__()
- else:
- raise InterfaceError, 'do not know how to handle type %s' % type(x)
-
- return x
-
-def _quoteparams(s, params):
- if hasattr(params, 'has_key'):
- x = {}
- for k, v in params.items():
- x[k] = _quote(v)
- params = x
- else:
- params = tuple(map(_quote, params))
-
- return s % params
+try:
+ _quote = _pg.quote_fast
+ _quoteparams = _pg.quoteparams_fast
+except (NameError, AttributeError):
+ def _quote(x):
+ if type(x) == DateTime.DateTimeType:
+ x = str(x)
+ if type(x) == types.StringType:
+ x = "'" + string.replace(
+ string.replace(str(x), '\\', '\\\\'), "'", "''") + "'"
+
+ elif type(x) in (types.IntType, types.LongType, types.FloatType):
+ pass
+ elif x is None:
+ x = 'NULL'
+ elif type(x) in (types.ListType, types.TupleType):
+ x = '(%s)' % string.join(map(lambda x: str(_quote(x)), x), ',')
+ elif hasattr(x, '__pg_repr__'):
+ x = x.__pg_repr__()
+ else:
+ raise InterfaceError, 'do not know how to handle type %s' % type(x)
+
+ return x
+
+ def _quoteparams(s, params):
+ if hasattr(params, 'has_key'):
+ x = {}
+ for k, v in params.items():
+ x[k] = _quote(v)
+ params = x
+ else:
+ params = tuple(map(_quote, params))
+
+ return s % params
### connection object