[DB-SIG] Transaction with DCOracle?

¹æ¹Î bangmin@NOTENHILL.com
Mon, 22 Jan 2001 09:33:00 +0900


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C0840A.DFDC3500
Content-Type: text/plain;
	charset="KS_C_5601-1987"

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?
 
thank you in advance.
 
Min.

------_=_NextPart_001_01C0840A.DFDC3500
Content-Type: text/html;
	charset="KS_C_5601-1987"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DKS_C_5601-1987">


<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC size=3D4><SPAN =
class=3D868481200-22012001>Dear python geeks..=20
</SPAN></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC size=3D4><SPAN=20
class=3D868481200-22012001>---------------------------------------------=
--------------</SPAN></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4>import DCOracle =
<BR>csor =3D=20
DCOracle.Connect('...') <BR>try: =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;csor.execute('<SPAN=20
class=3D868481200-22012001>INSERT</SPAN>&nbsp;<SPAN=20
class=3D868481200-22012001>INTO</SPAN> history&nbsp;<SPAN=20
class=3D868481200-22012001>VALUES</SPAN>(\'20010114\', 123123)')=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;csor.execute('<SPAN=20
class=3D868481200-22012001>INSERT</SPAN>&nbsp;<SPAN=20
class=3D868481200-22012001>INTO</SPAN> history&nbsp;<SPAN=20
class=3D868481200-22012001>VALUES</SPAN>(\'20010114\', 123123)')=20
<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;csor.commit() =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;print=20
'<SPAN class=3D868481200-22012001>commit</SPAN>' <BR>except Exception:=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;csor.rollback() =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;print=20
'<SPAN class=3D868481200-22012001>rollback</SPAN>' <BR>csor.close()=20
<BR>-----------------------------------------------------------&nbsp;<BR=
><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>I've tried to=20
handle Exceptions to get transaction&nbsp;like =
that,</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>but I couldn't=20
roll back the sqls.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>you know, if the=20
first column in HISTORY table is a primary =
key,</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>the 2nd=20
row&nbsp;couldn't be inserted.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>and then i hope=20
python throws exception,&nbsp;rolls back so </SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>the 1st=20
row&nbsp;is not inserted.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>here's the error=20
msg.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001>---------------------------------------------=
-----------------------</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>Traceback=20
(innermost last):<BR>&nbsp; File "test.py", line 9, in=20
?<BR>&nbsp;&nbsp;&nbsp;&nbsp;csor.execute('<SPAN=20
class=3D868481200-22012001>INSERT</SPAN>&nbsp;<SPAN=20
class=3D868481200-22012001>INTO</SPAN> history&nbsp;<SPAN=20
class=3D868481200-22012001>VALUES</SPAN>(\'20010114\',=20
123123)')&nbsp;<BR></SPAN></FONT></FONT><FONT =
face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001>&nbsp; File =
"/usr/lib/python1.5/DCOracle/ociCurs.py",=20
line 299, in execute<BR>&nbsp;&nbsp;&nbsp; r =3D =
self._execute(params__,=20
kw)<BR>&nbsp; File "/usr/lib/python1.5/DCOracle/ociCurs.py", line 260, =
in=20
_execute<BR>&nbsp;&nbsp;&nbsp; if rc!=3D3129: self._error()<BR>&nbsp; =
File=20
"/usr/lib/python1.5/DCOracle/ociCurs.py", line 109, in=20
_error<BR>&nbsp;&nbsp;&nbsp; raise error, (rc,=20
oci_.OracleErrorMessage(self._c.lda, rc))<BR>oci.error: (1, 'ORA-00001: =
unique=20
constraint (POINT.PK_PN_HISTORY) violated')</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001>---------------------------------------------=
-----------------------</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT><FONT =
face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001>do&nbsp;i have to handle another=20
exception?</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN =
class=3D868481200-22012001>thank you in=20
advance.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D=B1=BC=B8=B2=C3=BC><FONT size=3D4><SPAN=20
class=3D868481200-22012001>Min.</SPAN></FONT></FONT></DIV></BODY></HTML>=


------_=_NextPart_001_01C0840A.DFDC3500--