RUNPROGRAM & SQLITE

Just starting out? Need help? Post your questions and find answers here.
Marvi
User
User
Posts: 17
Joined: Fri Oct 03, 2008 6:02 pm
Location: Milano

RUNPROGRAM & SQLITE

Post 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?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Marvi
User
User
Posts: 17
Joined: Fri Oct 03, 2008 6:02 pm
Location: Milano

Post 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.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Marvi
User
User
Posts: 17
Joined: Fri Oct 03, 2008 6:02 pm
Location: Milano

Post 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.
Post Reply