Re: "expecting string, unicode or buffer object" on executemany
Oliosi Riccardo <[email protected]>
| Newsgroups | gmane.comp.python.db.cx-oracle |
|---|---|
| Message-ID | <[email protected]> |
Hi, we are using:
- python: 2.6.6
- cx_Oracle: 5.1.2
The problem seems to be caused by an incorrect definition of numeric fields: I try to insert a record with a numeric values but wrote as a string (surrounded by double quotes).
If I use the instruction “execute” in a cycle I obtain an “invalid number” error from oracle (ORA-01722), but if I use the “executemany” the error is:
“expecting string, unicode or buffer object”
When I use my code into my program it works correctly, and the records are inserted in table without any errors, but if I extract the part for the attached example I receive the error code 1722…
To replicate the problem, I send you a code example (see attached).
Thanks a lot.
Riccardo
Here you can find the “create table” scripts:
CREATE TABLE "A_TEST" (
"Compagnia" NUMBER,
"Datavalutazione" DATE,
"Descr.compagnia" VARCHAR2(4000 BYTE),
"Tipovalutazione" VARCHAR2(4000 BYTE),
"Ramo" VARCHAR2(4000 BYTE),
"Struttura" VARCHAR2(4000 BYTE),
"Portafoglio" VARCHAR2(4000 BYTE),
"Descr.portafoglio" VARCHAR2(4000 BYTE),
"Prodotto" NUMBER,
"Descr.prodotto" VARCHAR2(4000 BYTE),
"Sottoprodotto" VARCHAR2(4000 BYTE),
"Descrsottoprodotto" VARCHAR2(4000 BYTE),
"Titolocodiceinterno" NUMBER,
"ISIN" VARCHAR2(4000 BYTE),
"Descr.titolo" VARCHAR2(4000 BYTE),
"Quantita" NUMBER,
"Valorecarico" NUMBER,
"Prezzocarico" NUMBER,
"Valoremercato" NUMBER,
"Prezzomercato" NUMBER,
"Plusmercato" NUMBER,
"Minusmercato" NUMBER,
"Plus_minusnegoziazione" NUMBER,
"Competenzadividendi" NUMBER,
"Competenzacedolare" NUMBER,
"Competenzascarti" NUMBER,
"Capitalemedio" NUMBER,
"Rendimentodiperiodo" NUMBER,
"Duration" NUMBER,
"Durationmodificata" NUMBER,
"Rendimentoeffettivolordo" NUMBER,
"Vitaresidua" NUMBER,
"RipresediValore" NUMBER,
"Minusresidue" NUMBER,
"Nominaleinizioperiodo" NUMBER,
"Pat.nettoannocorrente" NUMBER,
"Gruppotitolo" VARCHAR2(4000 BYTE),
"Categoriadibilancio" VARCHAR2(4000 BYTE),
"Descr.categoriadibilancio" VARCHAR2(4000 BYTE),
"Catt.ST.P.CL.1" VARCHAR2(4000 BYTE),
"Cod.Bloomberg" VARCHAR2(4000 BYTE),
"YellowKeyBloomberg" VARCHAR2(4000 BYTE),
"Index-linked" VARCHAR2(4000 BYTE),
"Tipoquotazione" VARCHAR2(4000 BYTE),
"Tipofondo" VARCHAR2(4000 BYTE),
"Fondo" VARCHAR2(4000 BYTE),
"Tipostrutturato" VARCHAR2(4000 BYTE),
"FondoArmonizzato" VARCHAR2(4000 BYTE),
"Dataemissione" DATE,
"Datascadenza" DATE,
"Prezzoemissione" NUMBER,
"Datarimborso" DATE,
"Prezzorimborso" NUMBER,
"Paeseemissione" VARCHAR2(4000 BYTE),
"AreaGeografica" VARCHAR2(4000 BYTE),
"ZonaA" VARCHAR2(4000 BYTE),
"Mnemonicoemittente" VARCHAR2(4000 BYTE),
"Settoreemittente" VARCHAR2(4000 BYTE),
"Descr.emittente" VARCHAR2(4000 BYTE),
"Capogruppoemittente" VARCHAR2(4000 BYTE),
"RatingMOODYS" VARCHAR2(4000 BYTE),
"RatingS&P" VARCHAR2(4000 BYTE),
"RatingFITCH" VARCHAR2(4000 BYTE),
"Ratingcalc." VARCHAR2(4000 BYTE),
"RatingMOODYSI.E." VARCHAR2(4000 BYTE),
"RatingSPIE" VARCHAR2(4000 BYTE),
"RatingFITCHIE" VARCHAR2(4000 BYTE),
"Ratingcal.cIE" VARCHAR2(4000 BYTE),
"Tipotasso" VARCHAR2(4000 BYTE),
"Periodicitacedola" VARCHAR2(4000 BYTE),
"Cedolacorrente" VARCHAR2(4000 BYTE),
"Tassocedola" NUMBER,
"Floor" NUMBER,
"Cap" NUMBER,
"Subordinato" VARCHAR2(4000 BYTE),
"Mercatodiquotazione" VARCHAR2(4000 BYTE),
"Divisaemissione" VARCHAR2(4000 BYTE),
"Descr.calcolorateo" VARCHAR2(4000 BYTE),
"Datagodimento" DATE,
"Tipopaese" VARCHAR2(4000 BYTE),
"Valorestoricodiv.ist." NUMBER,
"Valorestoricodiv.emi." NUMBER,
"Cambiodicarico" NUMBER,
"Capitalesociale" NUMBER,
"Collegamentoistituto" VARCHAR2(4000 BYTE),
"FondoAperto_Chiuso" VARCHAR2(4000 BYTE),
"FondoRiservato" VARCHAR2(4000 BYTE),
"ValoreNominalefineperiodo" NUMBER
)
From: avinash nandakumar [mailto:[email protected]]
Sent: martedì 23 settembre 2014 14:29
To: [email protected]
Cc: Oliosi Riccardo
Subject: Re: [cx-oracle-users] "expecting string, unicode or buffer object" on executemany
Hello Ricardo,
Can you send a sample insert statement (unicode) similar to one you are using.
Also can you inform which python/ cx-oracle and oracle version you are using.
Best Regards,
Avinash
On 9/23/2014 5:32 PM, Oliosi Riccardo wrote:
Hello everybody,
I have a strange error:
When I call:
cursor.executemany( self.__sql, self.__buffer )
where
self.__sql is an insert statement (unicode) and self.__buffer is a list of tuple, the execution throws an exception with the following message:
“expecting string, unicode or buffer object”
But if I substitute the executemany with a cycle:
for item in self.__buffer:
cursor.execute(self.__sql, item)
the script works without any problems.
Can anyone help me?
Thanks in advance.
Riccardo
______________________
Riccardo Oliosi
SIDFramework
Gruppo CAD IT
Tel. +39.045.82.11.111
Fax +39.045.82.11.110
[email protected]<mailto:[email protected]>
www.cadit.it<http://www.cadit.it/>
CAD IT S.p.A.
Sede legale: Via Torricelli, 44/A - 37136 Verona
C.S. € 4.669.600,00 i.v.
C.F./P.IVA e n. iscr. R.I. di VR 01992770238
R.E.A. di VR n. 210441
______________________
Questo messaggio, con gli eventuali allegati, contiene informazioni riservate o confidenziali. Chiunque lo ricevesse pur non essendone il destinatario è pregato di segnalarlo immediatamente al mittente, di cancellarlo dal proprio sistema e di non copiarlo, diffonderne il contenuto o utilizzarlo in alcun modo.
This e-mail and any files transmitted with it are confidential or privileged. If you are not the intended recipient of this e-mail, please notify the sender and delete it from your system immediately: you should not copy, disclose or use either it or its attachments in any way whatsoever.
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
cx-oracle-users mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/cx-oracle-users
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
cx-oracle-users mailing list
cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/cx-oracle-users
Test.py
(application/octet-stream, 8 KB)
import datetime
import cx_Oracle
if __name__ == '__main__':
sql = u"""
INSERT INTO A_TEST (
"Compagnia","Datavalutazione","Descr.compagnia","Tipovalutazione","Ramo","Struttura","Portafoglio","Descr.portafoglio","Prodotto","Descr.prodotto","Sottoprodotto","Descrsottoprodotto","Titolocodiceinterno","ISIN","Descr.titolo","Quantita","Valorecarico","Prezzocarico","Valoremercato","Prezzomercato","Plusmercato","Minusmercato","Plus_minusnegoziazione","Competenzadividendi","Competenzacedolare","Competenzascarti","Capitalemedio","Rendimentodiperiodo","Duration","Durationmodificata","Rendimentoeffettivolordo","Vitaresidua","RipresediValore","Minusresidue","Nominaleinizioperiodo","Pat.nettoannocorrente","Gruppotitolo","Categoriadibilancio","Descr.categoriadibilancio","Catt.ST.P.CL.1","Cod.Bloomberg","YellowKeyBloomberg","Index-linked","Tipoquotazione","Tipofondo","Fondo","Tipostrutturato","FondoArmonizzato","Dataemissione","Datascadenza","Prezzoemissione","Datarimborso","Prezzorimborso","Paeseemissione","AreaGeografica","ZonaA","Mnemonicoemittente","Settoreemittente","Descr.emittente","Capogruppoemittente","RatingMOODYS","RatingS&P","RatingFITCH","Ratingcalc.","RatingMOODYSI.E.","RatingSPIE","RatingFITCHIE","Ratingcal.cIE","Tipotasso","Periodicitacedola","Cedolacorrente","Tassocedola","Floor","Cap","Subordinato","Mercatodiquotazione","Divisaemissione","Descr.calcolorateo","Datagodimento","Tipopaese","Valorestoricodiv.ist.","Valorestoricodiv.emi.","Cambiodicarico","Capitalesociale","Collegamentoistituto","FondoAperto_Chiuso","FondoRiservato","ValoreNominalefineperiodo"
) VALUES (
:p0,:p1,:p2,:p3,:p4,:p5,:p6,:p7,:p8,:p9,:p10,:p11,:p12,:p13,:p14,:p15,:p16,:p17,:p18,:p19,:p20,:p21,:p22,:p23,:p24,:p25,:p26,:p27,:p28,:p29,:p30,:p31,:p32,:p33,:p34,:p35,:p36,:p37,:p38,:p39,:p40,:p41,:p42,:p43,:p44,:p45,:p46,:p47,:p48,:p49,:p50,:p51,:p52,:p53,:p54,:p55,:p56,:p57,:p58,:p59,:p60,:p61,:p62,:p63,:p64,:p65,:p66,:p67,:p68,:p69,:p70,:p71,:p72,:p73,:p74,:p75,:p76,:p77,:p78,:p79,:p80,:p81,:p82,:p83,:p84,:p85,:p86,:p87
)
"""
con = cx_Oracle.connect("user/pwd@server")
c = con.cursor()
buffer = [(14, datetime.datetime(2014, 5, 31, 0, 0), 'CATTOLICA PREVIDENZA', 'ASSICURATIVA ', 'VITA C ', 'IMMOBILIZZATI VITA C', 'CPGS3 ', 'CP PREVI ', '2', 'GESTIONE SEPARATA ', ' ', '', 800200745, 'DE0004771662 ', 'IBRD 0 12/20/15 ', '60000.0', '27744.87', 90.441000000000003, '30563.39', 99.628, '2818.52', None, None, None, None, '1814.32', '50899.74', 6.6102695220100003, '1558', '1555', 0.23100000000000001, '1558', None, None, '60000.0', None, 'OBBLIGAZIONI ', '1CIII3A ', 'TITOLI STATO QU', '1CIII3A ', 'COZZ2026057 ', 'CORP ', ' ', 'QUOTATO ', '', ' ', 'NO STRUTTURATO ', ' ', datetime.datetime(1985, 12, 19, 0, 0), datetime.datetime(2015, 12, 20, 0, 0), 13.0, datetime.datetime(2015, 12, 20, 0, 0), 100.0, 'SNA', ' ', 'S', 'WORLD BANK ', 'SOVRANAZIONALI ', 'WORLD BANK GROUP - INTL BK REC', 'ONU ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', ' ', 'ZERO COUPON ', ' ', None, None, None, ' ', 'FRANCOFORTE ', 'DEM ', '30/360 ANNUALE ', datetime.datetime(1985, 12, 19, 0, 0), 'OCSE ', '27744.87', '54264.35', 1.9558336369930729, None, 'NESSUNA RELAZIONE ', ' ', ' ', '60000.0'), (14, datetime.datetime(2014, 5, 31, 0, 0), 'CATTOLICA PREVIDENZA', 'ASSICURATIVA ', 'VITA C ', 'CIRCOLANTE VITA C ', 'CPGS3 ', 'CP PREVI ', '2', 'GESTIONE SEPARATA ', ' ', '', 800200753, 'DE0005557508 ', 'DEUTSCHE TELEKOM AG-REG ', '50000.0', '489699.18', 9.793984, '616250.0', 12.324999999999999, '126550.82', None, 5241.8299999999999, 39000.0, None, 0.0, '300622.13', 14.716757545429999, None, None, None, None, None, None, '40000.0', None, 'AZIONI ', '1CIII1A ', 'PART. SOC. QUOT', '1CIII1A ', 'EQ0018055600001000 ', 'EQUITY ', ' ', 'QUOTATO ', '', ' ', 'NO STRUTTURATO ', ' ', datetime.datetime(1900, 1, 1, 0, 0), datetime.datetime(1900, 1, 1, 0, 0), None, datetime.datetime(1900, 1, 1, 0, 0), None, 'DE ', ' ', 'S', 'DEUTSCHE TEL.AG', 'COMUNICAZIONI ', 'DEUTSCHE TELEKOM AG ', 'DEUTSCHE TEL.AG ', ' ', ' ', ' ', 'NA ', 'BAA1 ', 'BBB+ ', 'BBB+ ', 'BBB+ ', ' ', ' ', ' ', None, None, None, ' ', 'FRANCOFORTE ', 'EUR ', ' ', datetime.datetime(1900, 1, 1, 0, 0), 'OCSE ', '489699.18', '489699.18', 1.0, 4451175000.0, 'NESSUNA RELAZIONE ', ' ', ' ', '50000.0')]
# this is a "buffer" with correct number (without double quote)
# buffer = [(14, datetime.datetime(2014, 5, 31, 0, 0), 'CATTOLICA PREVIDENZA', 'ASSICURATIVA ', 'VITA C ', 'IMMOBILIZZATI VITA C', 'CPGS3 ', 'CP PREVI ', 2, 'GESTIONE SEPARATA ', ' ', '', 800200745, 'DE0004771662 ', 'IBRD 0 12/20/15 ', 60000.0, 27744.87, 90.441000000000003, 30563.39, 99.628, 2818.52, None, None, None, None, 1814.32, 50899.74, 6.6102695220100003, 1558, 1555, 0.23100000000000001, 1558, None, None, 60000.0, None, 'OBBLIGAZIONI ', '1CIII3A ', 'TITOLI STATO QU', '1CIII3A ', 'COZZ2026057 ', 'CORP ', ' ', 'QUOTATO ', '', ' ', 'NO STRUTTURATO ', ' ', datetime.datetime(1985, 12, 19, 0, 0), datetime.datetime(2015, 12, 20, 0, 0), 13.0, datetime.datetime(2015, 12, 20, 0, 0), 100.0, 'SNA', ' ', 'S', 'WORLD BANK ', 'SOVRANAZIONALI ', 'WORLD BANK GROUP - INTL BK REC', 'ONU ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', 'AAA ', ' ', 'ZERO COUPON ', ' ', None, None, None, ' ', 'FRANCOFORTE ', 'DEM ', '30/360 ANNUALE ', datetime.datetime(1985, 12, 19, 0, 0), 'OCSE ', 27744.87, 54264.35, 1.9558336369930729, None, 'NESSUNA RELAZIONE ', ' ', ' ', 60000.0), (14, datetime.datetime(2014, 5, 31, 0, 0), 'CATTOLICA PREVIDENZA', 'ASSICURATIVA ', 'VITA C ', 'CIRCOLANTE VITA C ', 'CPGS3 ', 'CP PREVI ', 2, 'GESTIONE SEPARATA ', ' ', '', 800200753, 'DE0005557508 ', 'DEUTSCHE TELEKOM AG-REG ', 50000.0, 489699.18, 9.793984, 616250.0, 12.324999999999999, 126550.82, None, 5241.8299999999999, 39000.0, None, 0.0, 300622.13, 14.716757545429999, 'N.A.', 'N.A.', None, 'N.A.', None, None, 40000.0, None, 'AZIONI ', '1CIII1A ', 'PART. SOC. QUOT', '1CIII1A ', 'EQ0018055600001000 ', 'EQUITY ', ' ', 'QUOTATO ', '', ' ', 'NO STRUTTURATO ', ' ', datetime.datetime(1900, 1, 1, 0, 0), datetime.datetime(1900, 1, 1, 0, 0), None, datetime.datetime(1900, 1, 1, 0, 0), None, 'DE ', ' ', 'S', 'DEUTSCHE TEL.AG', 'COMUNICAZIONI ', 'DEUTSCHE TELEKOM AG ', 'DEUTSCHE TEL.AG ', ' ', ' ', ' ', 'NA ', 'BAA1 ', 'BBB+ ', 'BBB+ ', 'BBB+ ', ' ', ' ', ' ', None, None, None, ' ', 'FRANCOFORTE ', 'EUR ', ' ', datetime.datetime(1900, 1, 1, 0, 0), 'OCSE ', 489699.18, 489699.18, 1.0, 4451175000.0, 'NESSUNA RELAZIONE ', ' ', ' ', 50000.0)]
try:
c.executemany(sql, buffer)
#for item in buffer:
# c.execute(sql,item)
con.commit()
except Exception, e:
con.rollback()
c.close()
con.close()
c = None