problem with import type field data

60 views
Skip to first unread message

dfpro...@gmail.com

unread,
Jul 27, 2016, 1:49:52 PM7/27/16
to web2py-users
good morning
first of all thanks and congratulations for the wonderful work that is web2py.

I just started using it and I have this problem.

writing on  db.py I created a SQLite database, a table (articles) and I imported data from an existing .dbf file with a  script, 

it happens that the "data" field (the date of price change);  if it is empty generates an exception, "ValueError: invalid literal for int () with base 10: '' if the field is full, everything ok.

The "data" field is in format year, month, day.  (looking with db browser)

I tried to import it via .csv files and even .sql 

This happens only on the imported data, the records registered by the form, everything ok.
I understand that the program understands that it is imported but should accept it as it is, do not try to convert it (I think)

I also imported with "db.articoli.import_from_csv_file (open ( 'z: /articoli.csv'))"

also as "migrate = false"

but is all useless :(

I can not find a solution, someone with a good heart can help me?

for the magic Massimo .... why do not you talk more about the Italian ?? :) 

tanks to all

Dave S

unread,
Jul 27, 2016, 3:39:41 PM7/27/16
to web2py-users


On Wednesday, July 27, 2016 at 10:49:52 AM UTC-7, dfpro...@gmail.com wrote:
good morning
first of all thanks and congratulations for the wonderful work that is web2py.

I just started using it and I have this problem.

writing on  db.py I created a SQLite database, a table (articles) and I imported data from an existing .dbf file with a  script, 

it happens that the "data" field (the date of price change);  if it is empty generates an exception, "ValueError: invalid literal for int () with base 10: '' if the field is full, everything ok.

The "data" field is in format year, month, day.  (looking with db browser)

Can you give the 1st line of the file, and an example line that's ok and one that isn't?
 Also the define_table() from your model file ... I take it you're using 'datetime' for the relevant field type.

I think the issue may be with the way in which "empty" is represented.


I tried to import it via .csv files and even .sql 

This happens only on the imported data, the records registered by the form, everything ok.
I understand that the program understands that it is imported but should accept it as it is, do not try to convert it (I think)


Well, it's trying to turn strings into non-string values (that is, something like "January 10 2001" into the binary number that the database uses to represent that), so conversion is necessary.  It would be the same for converting "134.56" into a DECIMAL field.

I also imported with "db.articoli.import_from_csv_file (open ( 'z: /articoli.csv'))"

also as "migrate = false"

but is all useless :(

I can not find a solution, someone with a good heart can help me?

for the magic Massimo .... why do not you talk more about the Italian ?? :) 

tanks to all


/dps
 
Message has been deleted

dfpro...@gmail.com

unread,
Jul 28, 2016, 8:31:17 AM7/28/16
to web2py-users
Tanks Dave,
 
this is a little extract .csv of the database,

together record ok saved via the web2py form, and also record imported from a dbf with db browser

id,codice,descriz,classmerc1,classmerc2,escluso,un_mis,sottosc,pesounit,litriunit,materiapri,editinpv,fornitore,codiceacci,pr_acq,percspese,perc_ric,cod_iva,pr_vend,listino01,listino02,listino03,listino04,dataaggpr,codccstato,camputente
14817,ok1,record ok without data,,,N,N,0,0.0,0.0,N,N,,,0.0,0.0,0.0,22,0.0,0.0,0.0,0.0,0.0,,,                              record generated from the form, OK
14818,ok2,record ok with data,,,N,N,0,0.0,0.0,N,N,,,0.0,0.0,0.0,22,0.0,0.0,0.0,0.0,0.0,2016-07-28,,                   record generated from the form,  OK
14769,007442,Aia fr Diavoletto Arrosto,00094,,N,N,0,0.5,0.0,N,,AIA,,1.8933,3.0,59.9,10,3.43,0.0,0.0,0.0,0.0,2015-10-01,,                record imported, not ok
   14771,007443,Sigma Sgrassatore ml 750,00306,,N,N,0,0.75,0.0,N,,SIGMA,,1.01,8.5,42.12,22,1.9,0.0,0.0,0.0,0.0,2015-08-11,,          record imported, not ok

the problem is on dataaggpr, i think but record ok and not ok are in the same format.
possible that only me i had this problem ? 
 
tanks very much
Daniele

dfpro...@gmail.com

unread,
Aug 2, 2016, 1:21:01 PM8/2/16
to web2py-users
no help ?

Dave S

unread,
Aug 2, 2016, 2:09:17 PM8/2/16
to web2py-users


On Tuesday, August 2, 2016 at 10:21:01 AM UTC-7, dfpro...@gmail.com wrote:
no help ?

Sorry, I didn't see anything on my first look, so I was waiting for someone else to chime in.

The symptoms in the message with the sample aren't quite the same as in the original post.  Are you getting the same error message?  If you are, what have you done to confirm that it is the date field that is in error?

Please post your define_table() for this .. that's a lot of fields to do by eyeballing.

/dps

Reply all
Reply to author
Forward
0 new messages