last day (14 days later) » 

9:24 AM
0
Q: unable to insert all records from csv file to database

vjnan369my app has to insert all records from csv file to database and display all records in database.but when i do that it missing some records in csv file while inserting into database.what might be the reason for this kind of behavior? here is my csv file records. records displayed in webview..it ...

 
What is the output of CSV.parse(csv_text, :headers => :true).length?
 
@thebenedict-it is 372 but it should be 387,it is not able to parse all records..
 
Ok -- if you open output.csv in a text editor, do you see 387 (or 388 with headers) lines?
 
in text editor it is not showing in proper format...each record exceed more than one line...
 
That's ok -- the lines may wrap but you should still be able to get a line count. If the CSV isn't private share it and I'll take a look. If not, what is the last record you see when you open the CSV in a text file?
 
9:24 AM
 
CSV parses fine
what does your controller look like?
 
actually my app should download a file and
inject the data into the database
 
Hmm. In rails console, what is Download.count ?
 
372
 
If you're certain the output.csv is the one you shared, and the code doesn't run an exception, I do't know
It looks correct to me
If it were me, I'd Download.destroy_all and try again just to make sure
 
9:33 AM
in my application every time i run Download.destroy_all and inject into database...
 
Ok, try this. Make a copy of your CSV as a backup, delete the first 20 records from the top, and import that - see how many records you get
 
ok..i will do that
 
Great, then post Download.count
An also, the output of Download.last
 
wow...it showing all records including missed records..
 
all the records?
 
9:43 AM
yes...except deleted records!
 
As in, including the 20 you deleted?
Ah, ok
 
didnt understand why this happend..
 
So it sounds like the data is good. You can probably get it working, then, by splitting the CSV into two pieces
but yeah, I don't understand why either
You might also try and delete 10 records (any number less than 15) and see if it still drops some
If you're interested in figuring out what's happening
 
ok..i will try it..thanks a lot...for your valuable time..can you post some answer...there so that i accept your answer
 
9:59 AM
No worries, just post the answer yourself if you figure it out in the end
Good luck
 

last day (14 days later) »