|
From: Billy G. A. <bal...@us...> - 2001-09-25 20:40:38
|
Update of /cvsroot/pypgsql/pypgsql
In directory usw-pr-cvs1:/tmp/cvs-serv8943
Modified Files:
PgSQL.py
Log Message:
25SEP2001 bga Changed the code so that a notice in the notice list will not
automatically generate an exception. The majority of these
notices are information and should not cause an exception to
be raised. Only in certain situation will a notice generate
an exception.
Index: PgSQL.py
===================================================================
RCS file: /cvsroot/pypgsql/pypgsql/PgSQL.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** PgSQL.py 2001/09/24 16:53:33 1.23
--- PgSQL.py 2001/09/25 20:40:32 1.24
***************
*** 30,33 ****
--- 30,38 ----
# Date Ini Description |
# --------- --- ------------------------------------------------------- |
+ # 25SEP2001 bga Changed the code so that a notice in the notice list |
+ # will not automatically generate an exception. The ma- |
+ # jority of these notices are information and should not |
+ # cause an exception to be raised. Only in certain situ- |
+ # ation will a notice generate an exception. |
# 24SEP2001 bga Changed the method used to quote strings. This new way |
# does not require the services of pgFixEsc, which was |
***************
*** 547,555 ****
return self.__type_cache[pgtype.value]
except KeyError:
_res = self.__conn.conn.query("SELECT typname, typprtlen, typelem "
"FROM pg_type "
"WHERE oid = %s" % pgtype.value)
! if len(self.__conn.notices) > 0:
raise Warning, self.__conn.notices.pop()
--- 552,561 ----
return self.__type_cache[pgtype.value]
except KeyError:
+ _nl = len(self.__conn.notices)
_res = self.__conn.conn.query("SELECT typname, typprtlen, typelem "
"FROM pg_type "
"WHERE oid = %s" % pgtype.value)
! if len(self.__conn.notices) != _nl:
raise Warning, self.__conn.notices.pop()
***************
*** 1578,1584 ****
if self.__closeCursors(1):
try:
self.conn.query("ROLLBACK WORK")
! while len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
except:
pass
--- 1584,1591 ----
if self.__closeCursors(1):
try:
+ _nl = len(self.conn.notices)
self.conn.query("ROLLBACK WORK")
! if len(self.conn.notices) != _nl:
! raise Warning, self.__conn.notices.pop()
except:
pass
***************
*** 1606,1616 ****
if self.__closeCursors():
self.__dict__["inTransaction"] = 0
! # Until the warning framework is in place, clear out the notices
! # before doing a commit. This will allow catching any noices
! # generated by the commit.
! while len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
res = self.conn.query("COMMIT WORK")
! if len(self.conn.notices) > 0:
raise Warning, self.conn.notices.pop()
if res.resultStatus != COMMAND_OK:
--- 1613,1619 ----
if self.__closeCursors():
self.__dict__["inTransaction"] = 0
! _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:
***************
*** 1630,1640 ****
if self.__closeCursors():
self.__dict__["inTransaction"] = 0
! # Until the warning framework is in place, clear out the notices
! # before doing a rollback. This will allow catching any noices
! # generated by the rollback.
! while len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
res = self.conn.query("ROLLBACK WORK")
! if len(self.conn.notices) > 0:
raise Warning, self.conn.notices.pop()
if res.resultStatus != COMMAND_OK:
--- 1633,1639 ----
if self.__closeCursors():
self.__dict__["inTransaction"] = 0
! _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:
***************
*** 1663,1667 ****
--- 1662,1672 ----
"Creation of large object failed - Connection is not open."
+ _nl = len(self.conn.notices)
+
_lo = self.conn.lo_creat(INV_READ | INV_WRITE)
+
+ if len(self.conn.notices) != _nl:
+ raise Warning, self.__conn.notices.pop()
+
if string:
_lo.open("w")
***************
*** 1669,1674 ****
_lo.close()
! if len(self.conn.notices) > 0:
! raise Warning, self.conn.notices.pop()
return _lo
--- 1674,1679 ----
_lo.close()
! if len(self.conn.notices) != _nl:
! raise Warning, self.conn.notices.pop()
return _lo
***************
*** 1692,1697 ****
oid = lobj.oid
res = self.conn.lo_unlink(oid)
! if len(self.conn.notices) > 0:
raise Warning, self.conn.notices.pop()
--- 1697,1703 ----
oid = lobj.oid
+ _nl = len(self.conn.notices)
res = self.conn.lo_unlink(oid)
! if len(self.conn.notices) != _nl:
raise Warning, self.conn.notices.pop()
***************
*** 1769,1774 ****
try:
self.conn.conn.query("CLOSE %s" % self.name)
- while len(self.conn.notices) > 0:
- _drop = self.conn.notices.pop()
except:
pass
--- 1775,1778 ----
***************
*** 1939,1946 ****
else:
if not self.conn.inTransaction:
self.conn.conn.query('BEGIN WORK')
self.conn.__dict__["inTransaction"] = 1
- if len(self.conn.notices) > 0:
- raise Warning, self.conn.notices.pop()
_qstr = "select %s(" % proc
--- 1943,1951 ----
else:
if not self.conn.inTransaction:
+ _nl = len(self.conn.notices)
self.conn.conn.query('BEGIN WORK')
+ if len(self.conn.notices) != _nl:
+ raise Warning, self.__conn.notices.pop()
self.conn.__dict__["inTransaction"] = 1
_qstr = "select %s(" % proc
***************
*** 1952,1955 ****
--- 1957,1962 ----
_qstr = '%s)' % _qstr[:-2]
+ _nl = len(self.conn.notices)
+
try:
self.res = self.conn.conn.query(_qstr)
***************
*** 1973,1978 ****
self.conn.__dict__["inTransaction"] = 0
self.conn._Connection__closeCursors()
- while len(self.conn.notices) > 0:
- _drop = self.conn.notices.pop()
raise OperationalError, msg
except InternalError, msg:
--- 1980,1983 ----
***************
*** 1983,1990 ****
raise InternalError, msg
! if len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
if _drop.find('transaction is aborted') > 0:
! raise Warning, _drop
self._rows_ = self.res.ntuples
--- 1988,1995 ----
raise InternalError, msg
! if len(self.conn.notices) != _nl:
! _drop = self.conn.notices[-1]
if _drop.find('transaction is aborted') > 0:
! raise Warning, self.conn.notices.pop()
self._rows_ = self.res.ntuples
***************
*** 2042,2049 ****
# so DROP TABLE/INDEX is ok.
else:
self.conn.conn.query('BEGIN WORK')
! self.conn.__dict__["inTransaction"] = 1
! if len(self.conn.notices) > 0:
raise Warning, self.conn.notices.pop()
if re_DQL.search(query) and \
--- 2047,2055 ----
# so DROP TABLE/INDEX is ok.
else:
+ _nl = len(self.conn.notices)
self.conn.conn.query('BEGIN WORK')
! if len(self.conn.notices) != _nl:
raise Warning, self.conn.notices.pop()
+ self.conn.__dict__["inTransaction"] = 1
if re_DQL.search(query) and \
***************
*** 2058,2065 ****
pass # not in transaction so DROP TABLE/INDEX is ok.
else:
self.conn.conn.query('BEGIN WORK')
! self.conn.__dict__["inTransaction"] = 1
! if len(self.conn.notices) > 0:
raise Warning, self.conn.notices.pop()
try:
--- 2064,2074 ----
pass # not in transaction so DROP TABLE/INDEX is ok.
else:
+ _nl = len(self.conn.notices)
self.conn.conn.query('BEGIN WORK')
! if len(self.conn.notices) != _nl:
raise Warning, self.conn.notices.pop()
+ self.conn.__dict__["inTransaction"] = 1
+
+ _nl = len(self.conn.notices)
try:
***************
*** 2092,2100 ****
# action has been aborted. Try to recover to a sane state.
if self.conn.inTransaction:
self.conn.conn.query('ROLLBACK WORK')
self.conn.__dict__["inTransaction"] = 0
self.conn._Connection__closeCursors()
- while len(self.conn.notices) > 0:
- _drop = self.conn.notices.pop()
raise OperationalError, msg
except InternalError, msg:
--- 2101,2110 ----
# action has been aborted. Try to recover to a sane state.
if self.conn.inTransaction:
+ _n = len(self.conn.notices)
self.conn.conn.query('ROLLBACK WORK')
+ if len(self.conn.notices) != _n:
+ raise Warning, self.__conn.notices.pop()
self.conn.__dict__["inTransaction"] = 0
self.conn._Connection__closeCursors()
raise OperationalError, msg
except InternalError, msg:
***************
*** 2105,2112 ****
raise InternalError, msg
! if len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
if _drop.find('transaction is aborted') > 0:
! raise Warning, _drop
if self.res.resultType == RESULT_DQL:
--- 2115,2122 ----
raise InternalError, msg
! if len(self.conn.notices) != _nl:
! _drop = self.conn.notices[-1]
if _drop.find('transaction is aborted') > 0:
! raise Warning, self.conn.notices.pop()
if self.res.resultType == RESULT_DQL:
***************
*** 2120,2129 ****
self._idx_ = 0
self.__makedesc__()
!
! if len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
if _drop.find('transaction is aborted') > 0:
! raise Warning, _drop
!
def executemany(self, query, parm_sequence):
if self.closed:
--- 2130,2139 ----
self._idx_ = 0
self.__makedesc__()
!
! if len(self.conn.notices) != _nl:
! _drop = self.conn.notices[-1]
if _drop.find('transaction is aborted') > 0:
! raise Warning, self.conn.notices.pop()
!
def executemany(self, query, parm_sequence):
if self.closed:
***************
*** 2154,2165 ****
pass # Still data in result buffer, use it.
elif self.closed == 0:
self.res = self.conn.conn.query("FETCH 1 FROM %s" % self.name)
self._rows_ = self.res.ntuples
self._idx_ = 0
! if len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
if _drop.find('transaction is aborted') > 0:
! raise Warning, _drop
return self.__fetchOneRow()
--- 2164,2176 ----
pass # Still data in result buffer, use it.
elif self.closed == 0:
+ _nl = len(self.conn.notices)
self.res = self.conn.conn.query("FETCH 1 FROM %s" % self.name)
self._rows_ = self.res.ntuples
self._idx_ = 0
! if len(self.conn.notices) != _nl:
! _drop = self.conn.notices[-1]
if _drop.find('transaction is aborted') > 0:
! raise Warning, self.conn.notices.pop()
return self.__fetchOneRow()
***************
*** 2199,2202 ****
--- 2210,2214 ----
# the PostgreSQL portal.
if self.closed == 0 and sz > 0:
+ _nl = len(self.conn.notices)
self.res = self.conn.conn.query("FETCH %d FROM %s" %
(sz, self.name))
***************
*** 2204,2211 ****
self._idx_ = 0
! if len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
if _drop.find('transaction is aborted') > 0:
! raise Warning, _drop
return self.__fetchManyRows(sz, _list)
--- 2216,2223 ----
self._idx_ = 0
! if len(self.conn.notices) != _nl:
! _drop = self.conn.notices[-1]
if _drop.find('transaction is aborted') > 0:
! raise Warning, self.conn.notices.pop()
return self.__fetchManyRows(sz, _list)
***************
*** 2235,2246 ****
# Fetch the remaining results from the PostgreSQL portal.
if self.closed == 0:
self.res = self.conn.conn.query("FETCH ALL FROM %s" % self.name)
self._rows_ = self.res.ntuples
self._idx_ = 0
! if len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
if _drop.find('transaction is aborted') > 0:
! raise Warning, _drop
return self.__fetchManyRows(self._rows_, _list)
--- 2247,2259 ----
# Fetch the remaining results from the PostgreSQL portal.
if self.closed == 0:
+ _nl = len(self.conn.notices)
self.res = self.conn.conn.query("FETCH ALL FROM %s" % self.name)
self._rows_ = self.res.ntuples
self._idx_ = 0
! if len(self.conn.notices) != _nl:
! _drop = self.conn.notices[-1]
if _drop.find('transaction is aborted') > 0:
! raise Warning, self.conn.notices.pop()
return self.__fetchManyRows(self._rows_, _list)
***************
*** 2261,2271 ****
if self.closed == 0:
self.res = self.conn.conn.query("MOVE BACKWARD ALL IN %s" %
self.name)
self._rows_ = 0
! if len(self.conn.notices) > 0:
! _drop = self.conn.notices.pop()
if _drop.find('transaction is aborted') > 0:
! raise Warning, _drop
self.__dict__["rowcount"] = -1
--- 2274,2285 ----
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
! if len(self.conn.notices) != _nl:
! _drop = self.conn.notices[-1]
if _drop.find('transaction is aborted') > 0:
! raise Warning, self.conn.notices.pop()
self.__dict__["rowcount"] = -1
|