Re: PyGreSQL and transactions

From: "Billy G(dot) Allie" <Bill(dot)Allie(at)mug(dot)org>
To: "Nagy Laszlo Zsolt , KLTE TTK pm1" <nagylzs(at)dragon(dot)klte(dot)hu>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PyGreSQL and transactions
Date: 2000-07-20 22:07:19
Message-ID: 200007202207.SAA20408@bajor.mug.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

"Nagy Laszlo Zsolt , KLTE TTK pm1" wrote:
>
> 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.)
>

I have a Python to PostgreSQL interface program that I am preparing to release.
It has the following features:

1. Support for cursors using 'DECLARE ... ' systax.
2. Support the following PostgreSQL typs as Python objects:
PG_BOOL, PG_INT2, PG_INT4, PG_INT8, PG_FLOAT4 PG_FLOAT8, PG_CHAR,
PG_VARCHAR, PG_TEXT, PG_BLOB (Large Objects), PG_NUMERIC
The PG_NUMERIC support include *, /, +, and - operators.
The PG_BLOB fully emulates a Python File Object except for truncate().
3. Support for PostgreSQL arrays. They are converted to/from Python lists on
input/output.
4. PostgreSQL notices are made available via the notices attribute of a
connection object. The
notices attribute is implemented as a list of notices such that
connection.notices.pop() will
return the first notice recieved from the back-end. Coalling pop() will
return the next
notice received, and so on.
5. Traps attempts to drop tables/indices, and unlinking large objects within
a transasction.
These actions are dangerous, since they can not be successfully rolled
back with the current
version of PostgreSQL. If the transactions were aborted or rolled back,
the database will be
left in a state where accessing the table, index, or large object that
was dropped will result
in an error because PostgreSQL can not access the file associated with
the table/index/LO.

I have been using the interface for about a week now without problems., but
have only been using it on UnixWare 7.0. If you are interested in using the
interface, I can send it to you and provide some assistance in porting it to
your environement (if needed).

> 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.
> >>>

Large Objects can only be opened and used in a transaction.
--
____ | Billy G. Allie | Domain....: Bill(dot)Allie(at)mug(dot)org
| /| | 7436 Hartwell | Compuserve: 76337,2061
|-/-|----- | Dearborn, MI 48126| MSN.......: B_G_Allie(at)email(dot)msn(dot)com
|/ |LLIE | (313) 582-1540 |

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Jason Earl 2000-07-21 17:28:29 Re: PyGreSQL and transactions
Previous Message Peter Mount 2000-07-20 18:45:44 Re: Bug in JDBC driver V. 7.0 ?