Thread: [cx-oracle-users] which row is causing problem ? (with executemany and cx_Oracle.DatabaseError)
Brought to you by:
atuining
From: Quiche O. <qui...@gm...> - 2011-10-20 13:49:19
|
Hello, I am trying to import millions of rows in a table with executemany. Fiew of them are rejected by oracle because of various problems (not null constraint, format number ...). If I do this : ################################################################## insert = """ INSERT INTO mytable (col1,col2,col3) VALUES (:1, :2, :3)""" L = [] reader = csv.reader(open(infile), delimiter=';') i=0 for row in reader: L.append(row) if(i>10000): try: cursor.prepare(insert) cursor.executemany(None, L) cursor.commit() i=0 except cx_Oracle.DatabaseError,exc: error, = exc.args mess="\nOracle-Error-Code:"+str(error.code) mess+="\nOracle-Error-Message:"+str(error.message) mess+="\nOracle-Error-context:"+str(error.context) mess+="\nTOUS:"+str(exc) sys.exit(mess) i+=1 ################################################################## I don't know the way to find out in the DatabaseError which row is causing the exception. Any idea ? |
From: Anthony T. <ant...@gm...> - 2011-10-20 16:04:55
|
Hi, On the error object there is an "offset" value which will give you that information. Also, the rowcount is set to the number of rows that were successfully processed if I recall correctly. Anthony On Thu, Oct 20, 2011 at 7:49 AM, Quiche Obscure <qui...@gm...> wrote: > Hello, > > I am trying to import millions of rows in a table with executemany. > > Fiew of them are rejected by oracle because of various problems (not null > constraint, format number ...). > > If I do this : > > ################################################################## > insert = """ INSERT INTO mytable (col1,col2,col3) VALUES (:1, :2, :3)""" > L = [] > reader = csv.reader(open(infile), delimiter=';') > i=0 > for row in reader: > L.append(row) > if(i>10000): > try: > cursor.prepare(insert) > cursor.executemany(None, L) > cursor.commit() > i=0 > except cx_Oracle.DatabaseError,exc: > error, = exc.args > mess="\nOracle-Error-Code:"+str(error.code) > mess+="\nOracle-Error-Message:"+str(error.message) > mess+="\nOracle-Error-context:"+str(error.context) > mess+="\nTOUS:"+str(exc) > sys.exit(mess) > i+=1 > > ################################################################## > > I don't know the way to find out in the DatabaseError which row is causing > the exception. > > Any idea ? > > ------------------------------------------------------------------------------ > The demand for IT networking professionals continues to grow, and the > demand for specialized networking skills is growing even more rapidly. > Take a complimentary Learning@Ciosco Self-Assessment and learn > about Cisco certifications, training, and career opportunities. > http://p.sf.net/sfu/cisco-dev2dev > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > |
From: <qui...@gm...> - 2011-10-20 19:06:15
|
Thank you for your reply.<br>I'll try this offset tomorrow (it is the evening where I leave) <br><span style="font-family:Prelude, Verdana, san-serif;"><br><br></span><span id="signature"><div style="font-family: arial, sans-serif; font-size: 12px;color: #999999">-- Envoyé depuis mon HP TouchPad</div></span><span style="color:navy; font-family:Prelude, Verdana, san-serif; "><hr align="left" style="width:75%">Le 20 oct. 2011 18:05, Anthony Tuininga <ant...@gm...> a écrit : <br></span>Hi, <br> <br>On the error object there is an "offset" value which will give you <br>that information. Also, the rowcount is set to the number of rows that <br>were successfully processed if I recall correctly. <br> <br>Anthony <br> <br>On Thu, Oct 20, 2011 at 7:49 AM, Quiche Obscure <br><qui...@gm...> wrote: <br>> Hello, <br>> <br>> I am trying to import millions of rows in a table with executemany. <br>> <br>> Fiew of them are rejected by oracle because of various problems (not null <br>> constraint, format number ...). <br>> <br>> If I do this : <br>> <br>> ################################################################## <br>> insert = """ INSERT INTO mytable (col1,col2,col3) VALUES (:1, :2, :3)""" <br>> L = [] <br>> reader = csv.reader(open(infile), delimiter=';') <br>> i=0 <br>> for row in reader: <br>> L.append(row) <br>> if(i>10000): <br>> try: <br>> cursor.prepare(insert) <br>> cursor.executemany(None, L) <br>> cursor.commit() <br>> i=0 <br>> except cx_Oracle.DatabaseError,exc: <br>> error, = exc.args <br>> mess="\nOracle-Error-Code:"+str(error.code) <br>> mess+="\nOracle-Error-Message:"+str(error.message) <br>> mess+="\nOracle-Error-context:"+str(error.context) <br>> mess+="\nTOUS:"+str(exc) <br>> sys.exit(mess) <br>> i+=1 <br>> <br>> ################################################################## <br>> <br>> I don't know the way to find out in the DatabaseError which row is causing <br>> the exception. <br>> <br>> Any idea ? <br>> <br>> ------------------------------------------------------------------------------ <br>> The demand for IT networking professionals continues to grow, and the <br>> demand for specialized networking skills is growing even more rapidly. <br>> Take a complimentary Learning@Ciosco Self-Assessment and learn <br>> about Cisco certifications, training, and career opportunities. <br>> http://p.sf.net/sfu/cisco-dev2dev <br>> _______________________________________________ <br>> cx-oracle-users mailing list <br>> cx-...@li... <br>> https://lists.sourceforge.net/lists/listinfo/cx-oracle-users <br>> <br>> <br> <br>------------------------------------------------------------------------------ <br>The demand for IT networking professionals continues to grow, and the <br>demand for specialized networking skills is growing even more rapidly. <br>Take a complimentary Learning@Ciosco Self-Assessment and learn <br>about Cisco certifications, training, and career opportunities. <br>http://p.sf.net/sfu/cisco-dev2dev <br>_______________________________________________ <br>cx-oracle-users mailing list <br>cx-...@li... <br>https://lists.sourceforge.net/lists/listinfo/cx-oracle-users |