[DB-SIG] Transaction with DCOracle?
chris@onca.catsden.net
chris@onca.catsden.net
Sun, 21 Jan 2001 16:32:56 -0800 (PST)
On Mon, 22 Jan 2001, [euc-kr] ¹æ¹Î wrote:
> Dear python geeks..
>
> -----------------------------------------------------------
> import DCOracle
> csor = DCOracle.Connect('...')
> try:
> csor.execute('INSERT INTO history VALUES(\'20010114\', 123123)')
>
> csor.execute('INSERT INTO history VALUES(\'20010114\', 123123)')
>
> csor.commit()
> print 'commit'
> except Exception:
> csor.rollback()
> print 'rollback'
> csor.close()
> -----------------------------------------------------------
>
> I've tried to handle Exceptions to get transaction like that,
> but I couldn't roll back the sqls.
>
> you know, if the first column in HISTORY table is a primary key,
> the 2nd row couldn't be inserted.
>
> and then i hope python throws exception, rolls back so
> the 1st row is not inserted.
>
> here's the error msg.
>
> --------------------------------------------------------------------
> Traceback (innermost last):
> File "test.py", line 9, in ?
> csor.execute('INSERT INTO history VALUES(\'20010114\', 123123)')
> File "/usr/lib/python1.5/DCOracle/ociCurs.py", line 299, in execute
> r = self._execute(params__, kw)
> File "/usr/lib/python1.5/DCOracle/ociCurs.py", line 260, in _execute
> if rc!=3129: self._error()
> File "/usr/lib/python1.5/DCOracle/ociCurs.py", line 109, in _error
> raise error, (rc, oci_.OracleErrorMessage(self._c.lda, rc))
> oci.error: (1, 'ORA-00001: unique constraint (POINT.PK_PN_HISTORY)
> violated')
> --------------------------------------------------------------------
>
> do i have to handle another exception?
Without going through the library myself (dont use Oracle myself), I'd
have to guess that oci.error is not a descendant of Exception. (Bad
library writer, Bad! :)
Try changing it to "except oci.error:" or just plain "except:"
("`-/")_.-'"``-._ Ch'marr, a.k.a.
. . `; -._ )-;-,_`) Chris Cogdon <chmarr@furry.org.au>
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.' FC1.3: FFH3cmA+>++C++D++H++M++P++R++T+++WZ++Sm++
((,.-' ((,/ fL RLCT acl+++d++e+f+++h++i++++jp-sm++