From: Billy G. A. <bal...@us...> - 2003-10-23 02:50:33
|
Update of /cvsroot/pypgsql/pypgsql/pyPgSQL In directory sc8-pr-cvs1:/tmp/cvs-serv3091/pyPgSQL Modified Files: PgSQL.py Log Message: 20OCT2003 bga - Fixed the quoting of lists/tuples passed in to the cursor.execute method for use with the SQL 'IN' opertor. ALso cleaned up the handling of parameters in cursor.execute(). Index: PgSQL.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/pyPgSQL/PgSQL.py,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** PgSQL.py 14 Jul 2003 21:19:20 -0000 1.35 --- PgSQL.py 22 Oct 2003 05:27:49 -0000 1.36 *************** *** 30,33 **** --- 30,37 ---- # Date Ini Description | # --------- --- ------------------------------------------------------- | + # 20OCT2003 bga - Fixed the quoting of lists/tuples passed in to the | + # cursor.execute method for use with the SQL 'IN' oper- | + # tor. ALso cleaned up the handling of parameters in | + # cursor.execute(). | # 05JUL2003 bga - Fixed a problem with PgNumeric where an exception can | # be thrown if the stated scale and precision of the | *************** *** 2251,2258 **** if value is None: ! return 'NULL' ! elif hasattr(value, '_quote'): ! return value._quote() ! elif type(value) is DateTimeType: return "'%s'" % value elif type(value) is DateTimeDeltaType: --- 2255,2266 ---- if value is None: ! return 'NULL' ! ! try: ! return value._quote() ! except AttributeError: ! pass ! ! if type(value) is DateTimeType: return "'%s'" % value elif type(value) is DateTimeDeltaType: *************** *** 2260,2263 **** --- 2268,2275 ---- elif isinstance(value, StringType): return PgQuoteString(value) + elif type(value) in [DictType, ListType, TupleType]: + return _quoteall(value) + elif isinstance(value, PgResultSet): + return _quoteall(value) elif isinstance(value, LongType): return str(value) *************** *** 2280,2284 **** t = (_quote(vdict), ) elif type(vdict) in [ListType, TupleType]: ! t = tuple(map(_quote, vdict)) else: raise TypeError, \ --- 2292,2298 ---- t = (_quote(vdict), ) elif type(vdict) in [ListType, TupleType]: ! t = "(" + \ ! reduce(lambda x, y: x + ", " + y, tuple(map(_quote, vdict))) + \ ! ")" else: raise TypeError, \ *************** *** 2988,2992 **** self.closed = 1 ! def execute(self, query, *parms): if self.closed: raise InterfaceError, "execute failed - the cursor is closed." --- 3002,3012 ---- self.closed = 1 ! def execute(self, *parms): ! if len(parms) == 0: ! raise TypeError, "execute() takes at least 2 arguments (1 given)" ! else: ! query = parms[0] # Get the query from the list of parameters ! parms = parms[1:] # and adjust the parameter list. ! if self.closed: raise InterfaceError, "execute failed - the cursor is closed." *************** *** 3038,3049 **** self.res = self.conn.conn.query(_qstr) else: ! if len(parms) == 1 and \ ! (type(parms[0]) in [DictType, ListType, TupleType] or \ ! isinstance(parms[0], PgResultSet)): ! parms = (self.__unicodeConvert(parms[0]),) ! parms = _quoteall(parms[0]) ! else: ! parms = self.__unicodeConvert(parms) ! parms = tuple(map(_quote, parms)); self.res = self.conn.conn.query(_qstr % parms) self._rows_ = self.res.ntuples --- 3058,3063 ---- self.res = self.conn.conn.query(_qstr) else: ! parms = self.__unicodeConvert(parms) ! parms = tuple(map(_quote, parms)); self.res = self.conn.conn.query(_qstr % parms) self._rows_ = self.res.ntuples |