pyPgSql there is already a transaction in progres
someone
petshmidt at googlemail.com
Tue Jun 2 09:32:46 EDT 2009
Hi,
I'm using pyPgSQL for accessing Postgres and do some update and select
queries.
and getting WARNING: there is already a transaction in progress if I
run runUpdate more than once.
So, what happens is following:
1. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); --
__existRecord
2. BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; -- __delQuery
3. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); --
again __existRecord
and here I'm getting the warning.
Can anyone explain me please what the problem is? I do select, then
delete transaction and then select again which doesn't work
Regards, Pet
class Bla:
def __init__:
pass
def runUpdate(self, number=5):
data = {}
data = self.__getUpdateItems(number)
for row in data:
try:
if self.__existRecord(row['q']):
self.__delQuery(row['q'])
except Exception, e:
print "Exception", e
def __delQuery(self, name):
query = """
BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT;
"""
try:
self.db.execute(query, name)
except Exception, e:
print "Exception: ", e
return True
def __existRecord(self, search):
query = """
SELECT address FROM address WHERE LOWER(address) = LOWER
(%s);
"""
try:
self.db.execute(query, search)
except Exception, e:
print "Exception: ", e
return self.db.fetchall()
def __getUpdateItems(self,number=5):
values = [number]
query = """
SELECT * FROM failed
WHERE id IS NULL
ORDER BY up DESC
LIMIT %s;
"""
result = []
try:
self.db.execute(query, *values)
result = self.db.fetchall()
except Exception, e:
print "Exception getUpdateItems: ", e
return result
More information about the Python-list
mailing list