Re: [cx-oracle-users] insert/update/delete returning state
Brought to you by:
atuining
From: Amaury F. d'A. <ama...@gm...> - 2013-03-13 12:27:26
|
Hi, 2013/3/12 Jose Soares <jos...@al...> > Hi all, > > I'm trying to returning UPDATE/INSERT/DELETE state. > > Is there a way to know the state of an UPDATE, for example, > if it fails or success, like in the following example? > > import cx_Oracle > DBURI = "sfa/5Y@16.3:1521/em" > connection = cx_Oracle.connect(DBURI) > cursor = connection.cursor() > success = cursor.execute("UPDATE TEST set id=17 where id=16") > print success > There are two kinds of "successes": - the first one is when the statement was executed without error. In case of failure, an exception will be raised. - the other one is when the statement actually updated something. For this you can look at "cursor.rowcount", this contains the number of updated rows. In your case, it will probably be zero or one. Hope this helps, -- Amaury Forgeot d'Arc |