aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/python/pgdb.py
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-03-05 02:01:44 +0000
committerBruce Momjian <bruce@momjian.us>2002-03-05 02:01:44 +0000
commitfef790cc0371b7521d868d5fc8037a4ea0d9b40e (patch)
tree552821344bd1bcf6c00d99892a561620dec255d4 /src/interfaces/python/pgdb.py
parent14b05248ccc3b3598ef6bb4d1617bb08dce074f1 (diff)
downloadpostgresql-fef790cc0371b7521d868d5fc8037a4ea0d9b40e.tar.gz
postgresql-fef790cc0371b7521d868d5fc8037a4ea0d9b40e.zip
Back out python patch:
Elliot Lee wrote: > This patch to the python bindings adds C versions of the often-used query > args quoting routines, as well as support for quoting lists e.g. > dbc.execute("SELECT * FROM foo WHERE blah IN %s", ([1,2,3],))
Diffstat (limited to 'src/interfaces/python/pgdb.py')
-rw-r--r--src/interfaces/python/pgdb.py58
1 files changed, 26 insertions, 32 deletions
diff --git a/src/interfaces/python/pgdb.py b/src/interfaces/python/pgdb.py
index 48f21ea5f2c..85ff7656c69 100644
--- a/src/interfaces/python/pgdb.py
+++ b/src/interfaces/python/pgdb.py
@@ -260,38 +260,32 @@ class pgdbCursor:
pass
-try:
- _quote = _pg.quote_fast
- _quoteparams = _pg.quoteparams_fast
-except NameError:
- 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 type(x) in (types.ListType, types.TupleType):
- return '(%s)' % ','.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
+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
### connection object