Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling multiple commands in SQLite3 from Command Prompt

I want to be able to make a batchfile that will loop through every file in a directory and import it inside SQlite3. The problem I have is that SQlite3 does not accept multiple commands from command prompt/batch, only 1 command.

What I have tried is :

 for %%f in (./tmp/*.csv) do (
     echo %%f
     sqlite3 database.db ".separator '|'" ".import './tmp/%%f' Dirs"
 ) 

And I get a too many options error, as it is only expecting a single command, while I need more than 1.

I also cannot write a second text file to be called by sqlite3 as the file being imported will change for every iteration.

Help would be appreciated.

like image 261
fysloc Avatar asked Oct 04 '22 10:10

fysloc


1 Answers

You can use the option -separator to set the separator (whose default already is |).

If you'd really need to execute multiple commands, you could write them to a file and .read that, or echo all of them and pipe them into sqlite3.

like image 144
CL. Avatar answered Oct 13 '22 11:10

CL.