--- postgresql-7.2/src/interfaces/python/pgdb.py.sopwith Thu Jun 14 22:23:18 2001 +++ postgresql-7.2/src/interfaces/python/pgdb.py Tue Mar 12 15:24:08 2002 @@ -260,32 +260,40 @@ pass -def _quote(x): - if type(x) == types.StringType: - x = "'" + string.replace( - string.replace(str(x), '\\', '\\\\'), "'", "''") + "'" +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)) - 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 + return s % params ### connection object