Re: PyGreSQL and transactions

From: Jason Earl <jdearl(at)yahoo(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PyGreSQL and transactions
Date: 2000-07-21 17:28:29
Message-ID: 20000721172829.11425.qmail@web118.yahoomail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

"Nagy Laszlo Zsolt , KLTE TTK pm1"
<nagylzs(at)dragon(dot)klte(dot)hu> writes:

> Hi all.
>
> I'm writting a text-based server program with
PyGreSQL.
> My first problem follows:
>
> >>> import pg
> >>> db =
pg.DB('gandalf','localhost',5432,None,None,'gandalf','')
> >>> db.query('BEGIN')
> >>> db.query("INSERT INTO tbl(s) VALUES('value1')")
> NOTICE: current transaction is aborted, queries
ignored until end of transaction block
> >>> db.query('commit')
> >>>
>
> The notice was sent to stderr, it seems that I have
no way to catch
> it. There is getnotify(), but there is no
getnotice(). I must catch
> it, because my server must know if the operation was
successful. (It
> is in a multi-tier application's middle, and sends
back a message
> about the operation.)

Using both the older 2.4 version of PyGreSQL and the
newer 3.1 version
that I am using you can catch these errors with a
try/except block:

db.query('BEGIN')
try:
db.query("INSERT INTO tbl(s) VALUES('value1')")
except (pg.error,), detail:
print "The transaction has been aborted\n %s" %
(detail,)
db.query('ABORT') #not necessary

> Second problem:
>
> >>> lo = db.locreate(pg.INV_WRITE)
> >>> lo
> Closed large object, oid 18863
> >>> lo.open(pg.INV_WRITE)
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> IOError: can't open large object.
> >>>
>
> I have compiled the PyGreSQL module without
-DNO_LARGE.

You need to encapsulate your large object access in a
transaction try
starting with a:

db.query('BEGIN')

and ending it with:

db.query('COMMIT')

> Thank in advance:
>
> Laszlo Nagy
> nagylzs(at)delfin(dot)klte(dot)hu

I hope this helps.

Jason

--
The single most useful thing about the Internet is
that it facilitates
using Linux. To use Linux, you need so much goddamn
technical
information that if you don't have a really good
source of technical
support, you're just screwed. -- Neal Stephenson

__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail Free email you can access from anywhere!
http://mail.yahoo.com/

Browse pgsql-interfaces by date

  From Date Subject
Next Message george stewart 2000-07-23 21:52:45 Anyway in JDBC to dectect if DB supports pre-compilation
Previous Message Billy G. Allie 2000-07-20 22:07:19 Re: PyGreSQL and transactions