Skip to content

Commit d3337c6

Browse files
committed
> 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
1 parent a7ade2b commit d3337c6

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

src/interfaces/python/pgdb.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -260,32 +260,40 @@ def setoutputsize(self, size, col = 0):
260260
pass
261261

262262

263-
def _quote(x):
264-
if type(x) == types.StringType:
265-
x = "'" + string.replace(
266-
string.replace(str(x), '\\', '\\\\'), "'", "''") + "'"
267-
268-
elif type(x) in (types.IntType, types.LongType, types.FloatType):
269-
pass
270-
elif x is None:
271-
x = 'NULL'
272-
elif hasattr(x, '__pg_repr__'):
273-
x = x.__pg_repr__()
274-
else:
275-
raise InterfaceError, 'do not know how to handle type %s' % type(x)
276-
277-
return x
278-
279-
def _quoteparams(s, params):
280-
if hasattr(params, 'has_key'):
281-
x = {}
282-
for k, v in params.items():
283-
x[k] = _quote(v)
284-
params = x
285-
else:
286-
params = tuple(map(_quote, params))
287-
288-
return s % params
263+
try:
264+
_quote = _pg.quote_fast
265+
_quoteparams = _pg.quoteparams_fast
266+
except (NameError, AttributeError):
267+
def _quote(x):
268+
if type(x) == DateTime.DateTimeType:
269+
x = str(x)
270+
if type(x) == types.StringType:
271+
x = "'" + string.replace(
272+
string.replace(str(x), '\\', '\\\\'), "'", "''") + "'"
273+
274+
elif type(x) in (types.IntType, types.LongType, types.FloatType):
275+
pass
276+
elif x is None:
277+
x = 'NULL'
278+
elif type(x) in (types.ListType, types.TupleType):
279+
x = '(%s)' % string.join(map(lambda x: str(_quote(x)), x), ',')
280+
elif hasattr(x, '__pg_repr__'):
281+
x = x.__pg_repr__()
282+
else:
283+
raise InterfaceError, 'do not know how to handle type %s' % type(x)
284+
285+
return x
286+
287+
def _quoteparams(s, params):
288+
if hasattr(params, 'has_key'):
289+
x = {}
290+
for k, v in params.items():
291+
x[k] = _quote(v)
292+
params = x
293+
else:
294+
params = tuple(map(_quote, params))
295+
296+
return s % params
289297

290298
### connection object
291299

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy