From: Billy G. A. <bal...@us...> - 2002-12-01 22:12:33
|
Update of /cvsroot/pypgsql/pypgsql/pyPgSQL In directory sc8-pr-cvs1:/tmp/cvs-serv18798/pyPgSQL Modified Files: PgSQL.py Log Message: 01DEC2002 bga - Fixed problems with new __setupTransaction function: 1. Made it a method of Connection, not Cursor. 2. inTransaction was only set if TransactionLevel was set. - Fixed instances where method name was incorrect: Connection__gcCursor -> _Connection__gcCursor Connection__closeCursor -> _Connection__closeCursor - Cleaned up code where there was unneeded references to conn in Connection class. Index: PgSQL.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/pyPgSQL/PgSQL.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** PgSQL.py 1 Dec 2002 21:45:10 -0000 1.24 --- PgSQL.py 1 Dec 2002 22:12:30 -0000 1.25 *************** *** 30,33 **** --- 30,42 ---- # Date Ini Description | # --------- --- ------------------------------------------------------- | + # 01DEC2002 bga - Fixed problems with new __setupTransaction function: | + # 1. Made it a method of Connection, not Cursor. | + # 2. inTransaction was only set if TransactionLevel was | + # set. | + # - Fixed instances where method name was incorrect: | + # Connection__gcCursor -> _Connection__gcCursor | + # Connection__closeCursor -> _Connection__closeCursor | + # - Cleaned up code where there was unneeded references | + # to conn in Connection class. | # 01DEC2002 gh - Handle the new '__quote__' method for arrays, too. | # - Still handle '_quote' methods for backwards compati- | *************** *** 37,41 **** # and PG_REFCURSOR oids. [Bug #845360] | # - Reference cursors are now type-casted into cursor ob- | ! # jects. # 27NOV2002 bga - Completed the emulation of a String object for the | # PgBytea and PgOther classes. This corrects several | --- 46,50 ---- # and PG_REFCURSOR oids. [Bug #845360] | # - Reference cursors are now type-casted into cursor ob- | ! # jects. | # 27NOV2002 bga - Completed the emulation of a String object for the | # PgBytea and PgOther classes. This corrects several | *************** *** 2289,2293 **** --- 2298,2314 ---- i.close() + def __setupTransaction(self): + """ + __setupTransaction() + Internal routine that will set up a transaction for this connection.\n""" + self.conn.query("BEGIN WORK") + if self.TransactionLevel != "": + self.conn.query('SET TRANSACTION ISOLATION LEVEL %s' % + self.TransactionLevel) + if len(self.notices) != _nl: + raise Warning, self.notices.pop() + self.__dict__["inTransaction"] = 1 + def close(self): """ *************** *** 2304,2309 **** _nl = len(self.conn.notices) self.conn.query("ROLLBACK WORK") ! if len(self.conn.notices) != _nl: ! raise Warning, self.conn.notices.pop() except: pass --- 2325,2330 ---- _nl = len(self.conn.notices) self.conn.query("ROLLBACK WORK") ! if len(self.notices) != _nl: ! raise Warning, self.notices.pop() except: pass *************** *** 2334,2339 **** _nl = len(self.conn.notices) res = self.conn.query("COMMIT WORK") ! if len(self.conn.notices) != _nl: ! raise Warning, self.conn.notices.pop() if res.resultStatus != COMMAND_OK: raise InternalError, "Commit failed - reason unknown." --- 2355,2360 ---- _nl = len(self.conn.notices) res = self.conn.query("COMMIT WORK") ! if len(self.notices) != _nl: ! raise Warning, self.notices.pop() if res.resultStatus != COMMAND_OK: raise InternalError, "Commit failed - reason unknown." *************** *** 2354,2359 **** _nl = len(self.conn.notices) res = self.conn.query("ROLLBACK WORK") ! if len(self.conn.notices) != _nl: ! raise Warning, self.conn.notices.pop() if res.resultStatus != COMMAND_OK: raise InternalError, \ --- 2375,2380 ---- _nl = len(self.conn.notices) res = self.conn.query("ROLLBACK WORK") ! if len(self.notices) != _nl: ! raise Warning, self.notices.pop() if res.resultStatus != COMMAND_OK: raise InternalError, \ *************** *** 2381,2400 **** "Creation of large object failed - Connection is not open." ! _nl = len(self.conn.notices) ! # Ensure that we are in a transaction for working with large objects if not self.inTransaction: ! self.conn.query("BEGIN WORK") ! if self.conn.TransactionLevel != "": ! self.conn.conn.query('SET TRANSACTION ISOLATION LEVEL %s' % ! self.conn.TransactionLevel) ! if len(self.conn.notices) != _nl: ! raise Warning, self.conn.notices.pop() ! self.conn.__dict__["inTransaction"] = 1 _lo = self.conn.lo_creat(INV_READ | INV_WRITE) ! if len(self.conn.notices) != _nl: ! raise Warning, self.__conn.notices.pop() if string: --- 2402,2416 ---- "Creation of large object failed - Connection is not open." ! _nl = len(self.notices) ! _ct = 0 # Ensure that we are in a transaction for working with large objects if not self.inTransaction: ! self.__setupTransaction() ! _ct = 1 _lo = self.conn.lo_creat(INV_READ | INV_WRITE) ! if len(self.notices) != _nl: ! raise Warning, self.notices.pop() if string: *************** *** 2403,2413 **** _lo.close() ! if len(self.conn.notices) != _nl: ! if not self.inTransaction: ! conn.conn.query("ROLLBACK WORK") raise Warning, self.conn.notices.pop() ! if not self.inTransaction: ! self.conn.query("COMMIT WORK") return _lo --- 2419,2430 ---- _lo.close() ! if len(self.notices) != _nl: ! if self.inTransaction: ! self.conn.query("ROLLBACK WORK") raise Warning, self.conn.notices.pop() ! if self.inTransaction: ! if _ct: # Only commit the transaction if we started it. ! self.conn.query("COMMIT WORK") return _lo *************** *** 2433,2438 **** _nl = len(self.conn.notices) res = self.conn.lo_unlink(oid) ! if len(self.conn.notices) != _nl: ! raise Warning, self.conn.notices.pop() return res --- 2450,2455 ---- _nl = len(self.conn.notices) res = self.conn.lo_unlink(oid) ! if len(self.notices) != _nl: ! raise Warning, self.notices.pop() return res *************** *** 2492,2496 **** # Only the first created cursor begins the transaction. if not self.conn.inTransaction: ! self.__setupTransaction() self.__dict__["PgResultSetClass"] = None --- 2509,2513 ---- # Only the first created cursor begins the transaction. if not self.conn.inTransaction: ! self.conn._Connection__setupTransaction() self.__dict__["PgResultSetClass"] = None *************** *** 2505,2519 **** self.__makedesc__() - def __setupTransaction(self): - _nl = len(self.conn.notices) - self.conn.conn.query("BEGIN WORK") - if self.conn.TransactionLevel != "": - self.conn.conn.query('SET TRANSACTION ISOLATION LEVEL %s' % - self.conn.TransactionLevel) - if len(self.conn.notices) != _nl: - raise Warning, self.conn.notices.pop() - self.conn.__dict__["inTransaction"] = 1 - - def __del__(self): # Ensure that the cursor is closed when it is deleted. This takes --- 2522,2525 ---- *************** *** 2737,2741 **** else: if not self.conn.inTransaction: ! self.__setupTransaction() proc = self.__unicodeConvert(proc) --- 2743,2747 ---- else: if not self.conn.inTransaction: ! self.conn._Connection__setupTransaction() proc = self.__unicodeConvert(proc) *************** *** 2777,2781 **** # An internal error occured. Try to get to a sane state. self.conn.__dict__["inTransaction"] = 0 ! self.conn.Connection__closeCursors_() self.conn.close() raise InternalError, msg --- 2783,2787 ---- # An internal error occured. Try to get to a sane state. self.conn.__dict__["inTransaction"] = 0 ! self.conn._Connection__closeCursors_() self.conn.close() raise InternalError, msg *************** *** 2840,2844 **** # so DROP TABLE/INDEX is ok. else: ! self.__setupTransaction() if re_DQL.search(query) and \ --- 2846,2850 ---- # so DROP TABLE/INDEX is ok. else: ! self.conn._Connection__setupTransaction() if re_DQL.search(query) and \ *************** *** 2853,2857 **** pass # not in transaction so DROP TABLE/INDEX is ok. else: ! self.__setupTransaction() _nl = len(self.conn.notices) --- 2859,2863 ---- pass # not in transaction so DROP TABLE/INDEX is ok. else: ! self.conn._Connection__setupTransaction() _nl = len(self.conn.notices) *************** *** 2899,2903 **** # An internal error occured. Try to get to a sane state. self.conn.__dict__["inTransaction"] = 0 ! self.conn.Connection__closeCursors_() self.conn.close() raise InternalError, msg --- 2905,2909 ---- # An internal error occured. Try to get to a sane state. self.conn.__dict__["inTransaction"] = 0 ! self.conn._Connection__closeCursors_() self.conn.close() raise InternalError, msg *************** *** 3063,3067 **** if self.closed == 0: _nl = len(self.conn.notices) ! self.res = self.conn.conn.query("MOVE BACKWARD ALL IN %s" % self.name) self._rows_ = 0 --- 3069,3073 ---- if self.closed == 0: _nl = len(self.conn.notices) ! self.res = self.conn.conn.query('MOVE BACKWARD ALL IN "%s"' % self.name) self._rows_ = 0 |