Page 1 of 1

RUNPROGRAM & SQLITE

Posted: Fri Oct 03, 2008 9:30 pm
by Marvi
Hallo guys, I'm new about this forum and quite new about PB.
I'm trying to write some code in order to load a CSV file into a sqlite database.

That's my import file (LOADCSV.TXT):

****************************
.separator ;
.import 'C:/sqlite/filetoupload.csv' tablename
******************************

That's my batch file LOAD.BAT
**************************
c:\sqlite\sqlite3.exe database.db < loadcsv.txt
*********************************

If I launch the LOAD.BAT, it works fine and uploads the data into the database.

If I try to put it into my PB code, using Runprogram, nothing happens.

RunProgram ("c:\sqlite\sqlite3.exe", "database.db < loadcsv.txt","","")

Also if I try to launch the batch file, nothing works.

RunProgram ("c:\sqlite\load.bat", "","","")

Can you help me?

Posted: Fri Oct 03, 2008 9:37 pm
by ts-soft

Code: Select all

RunProgram ("c:\sqlite\sqlite3.exe", #DQUOTE$ + "database.db < loadcsv.txt" + #DQUOTE$, "") 
you have to put parameter with spaces in dquotes!

Posted: Fri Oct 03, 2008 10:08 pm
by Marvi
Thanks, now something happens, it opens sqlite prompt, waiting for my input.
But it's not what I wish. I want that it runs the script, as batch file does.

Posted: Sat Oct 04, 2008 3:50 am
by pdwyer
You could do it yourself rather than rely on an external exe.

Load the CSV, parse it, get the first row for column heasers, create table, insert, close

Of course it's a bit more effort and more code but it would get rid of the external dependancy and mean you could add features later (like tab delimited text etc) too.

There is a Split() and a parse csv function in the tips section so you only need to write a little sql code.

Posted: Sat Oct 04, 2008 8:14 am
by Marvi
Yes, naturally I could and I'm going to do it. The fact is that Runprogram

is an useful tool when you're doing something on the fly, I'm

moving from MySql to Sqlite and while I'm changing the other parts of the

code I wanted to use it temporarily.