From: Billy G. A. <bal...@us...> - 2001-09-27 17:02:57
|
Update of /cvsroot/pypgsql/pypgsql In directory usw-pr-cvs1:/tmp/cvs-serv9615 Modified Files: PgSQL.py Log Message: 27SEP2001 bga Change code so that the escaping/quoting is different if the result is to be used to build PostgreSQL arrays. --- Modified all the Object._quote methods so that they now accept an option argument, forArray, which if set to 1 will cause escaping/quoting for PostgreSQL array use. --- Re-organized the code use to build PostgreSQL arrays. Index: PgSQL.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/PgSQL.py,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** PgSQL.py 2001/09/27 04:12:03 1.26 --- PgSQL.py 2001/09/27 17:02:53 1.27 *************** *** 30,33 **** --- 30,39 ---- # Date Ini Description | # --------- --- ------------------------------------------------------- | + # 27SEP2001 bga Change code so that the escaping/quoting is different | + # if the result is to be used to build PostgreSQL arrays. | + # --- Modified all the Object._quote methods so that they now | + # accept an option argument, forArray, which if set to 1 | + # will cause escaping/quoting for PostgreSQL array use. | + # --- Re-organized the code use to build PostgreSQL arrays. | # 26SEP2001 bga Added additional PostgreSQL types to BINARY, ROWID, etc | # --- Fixed problems associated with type casting. | *************** *** 544,548 **** elif _ftv == BINARY: if _ftv == PG_BYTEA: ! lst[_i] = PgBytea(PgUnQuoteBytea(lst[_i])) else: lst[_i] = PgLargeObject(self.conn, int(lst[_i])) --- 550,557 ---- elif _ftv == BINARY: if _ftv == PG_BYTEA: ! # There is no need to un-escape lst[_i], it's already been ! # done when the PostgreSQL array was converted to a list ! # via 'exec'. ! lst[_i] = PgBytea(lst[_i]) else: lst[_i] = PgLargeObject(self.conn, int(lst[_i])) *************** *** 627,633 **** # NOTE: A PgOther object will use the PgQuoteString() function in libpq. ! def _quote(self): if self.value: ! return PgQuoteString(self.value) return 'NULL' --- 636,642 ---- # NOTE: A PgOther object will use the PgQuoteString() function in libpq. ! def _quote(self, forArray=0): if self.value: ! return PgQuoteString(self.value, forArray) return 'NULL' *************** *** 677,683 **** # NOTE: A PgBytea object will use the PgQuoteBytea() function in libpq ! def _quote(self): if self.value: ! return PgQuoteBytea(self.value) return 'NULL' --- 686,692 ---- # NOTE: A PgBytea object will use the PgQuoteBytea() function in libpq ! def _quote(self, forArray=0): if self.value: ! return PgQuoteBytea(self.value, forArray) return 'NULL' *************** *** 879,885 **** return __sub__(other, self) ! def _quote(self): if self.__v: ! return "'%s'" % self.__fmtNumeric() return 'NULL' --- 888,897 ---- return __sub__(other, self) ! def _quote(self, forArray=0): if self.__v: ! if forArray: ! return '"%s"' % self.__fmtNumeric() ! else: ! return "'%s'" % self.__fmtNumeric() return 'NULL' *************** *** 1019,1025 **** return '$%s' % _s ! def _quote(self): if self.value: ! return "'%s'" % str(self.value) return 'NULL' --- 1031,1040 ---- return '$%s' % _s ! def _quote(self, forArray=0): if self.value: ! if forArray: ! return '"%s"' % str(self.value) ! else: ! return "'%s'" % str(self.value) return 'NULL' *************** *** 1184,1188 **** return str(self.value) ! def _quote(self): if self.value: s = str(self.value) --- 1199,1203 ---- return str(self.value) ! def _quote(self, forArray=0): if self.value: s = str(self.value) *************** *** 1386,1406 **** _v = list(_i) _j = _j + _handleArray(_v) + ',' elif type(_i) in [DateTime.DateTimeType, DateTime.DateTimeDeltaType]: _j = '%s"%s",' % (_j, _i) ! elif isinstance(_i, PgNumeric) or isinstance(_i, PgMoney): ! _j = '%s"%s",' % (_j, _i) ! elif type(_i) == PgInt2Type or \ ! type(_i) == PgLargeObjectType: ! _j = '%s%s,' % (_j, _i._quote) ! elif (type(PgInt8) == ClassType and isinstance(_i, PgInt8)) or \ ! type(_i) == PgInt8Type: _j = '%s%s,' % (_j, str(_i)) else: ! if isinstance(value, PgBytea) or isinstance(PgOther): ! _s = value._quote() ! else: ! _s = PgQuoteString(_i) ! # Note: _s will always be single-quoted. ! _j = '%s"%s",' % (_j, _s[1:-1]) return _j[:-1] + "}'" --- 1401,1412 ---- _v = list(_i) _j = _j + _handleArray(_v) + ',' + elif hasattr(_i, '_quote'): + _j = '%s%s,' % (_j, _i._quote(1)) elif type(_i) in [DateTime.DateTimeType, DateTime.DateTimeDeltaType]: _j = '%s"%s",' % (_j, _i) ! elif type(_i) == PgInt8Type or type(_i) == PgInt2Type: _j = '%s%s,' % (_j, str(_i)) else: ! _j = '%s%s,' % (_j, PgQuoteString(_i, 1)) return _j[:-1] + "}'" *************** *** 1422,1430 **** return _handleArray(list(value)) - if type(value) in [DateTimeType, DateTimeDeltaType]: - return "'%s'" % value - if hasattr(value, '_quote'): return value._quote() if type(value) == StringType: --- 1428,1436 ---- return _handleArray(list(value)) if hasattr(value, '_quote'): return value._quote() + + if type(value) in [DateTimeType, DateTimeDeltaType]: + return "'%s'" % value if type(value) == StringType: |