pass it the 'restore=True' to truncate the table before inserting. 
Otherwise, it doesn't appear that the CSV import would do an 'insert or 
update'.

On Monday, November 4, 2013 8:07:44 PM UTC-7, Sarbjit wrote:
>
> I am using import csv option to insert records in the database. When I use 
> the csv file from the web application, then  a single record is inserted in 
> the database with all the records being updated properly as per the headers.
>
> But If I try to use "import_from_csv_file" outside the web2py, it inserts 
> multiple records in the database. This seems to be an bug to me.
>
> Code for updating db outside web2py
>
> libraryPath = r'D:\web2py'
> dbPath = r'D:\web2py\applications\testapp\databases'
>
> import sys
> sys.path.append(libraryPath)
> from gluon import DAL
> db = DAL('sqlite://storage.sqlite',folder=dbPath,auto_import=True)
> table = db['person']
> file = r'D:\file.csv'
> table.import_from_csv_file(file)
> db.commit()
>
> On using the same file (csv file) using the web2py, it works as expected, 
> code :-
>
> file = request.vars.csvfile.file
> table.import_from_csv_file(file)
>
> Can some one please comment on this behavior, what am I missing here?
>
> -Sarbjit
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to