views:

12

answers:

1

Hi all,

Here is my question, when interacting with Sqlite 3 through terminal, you can execute SQL statements stored in a txt file by executing this command:

 .read filename

Is there a way to do such thing through Obj-C code? i.e. I've got a sqlite3 db file connected in the code, and i'd like to run a script file programmatically.

Thanks in advanced :)

A: 

You could forward the content of the file line by line, or in whole to the function exec

schoetbi
Thanks for the reply, so, I guess that means I'll have to read the file into string myself and exec the whole lot as one big SQL statement then?
Sunny Ho
That is the only solution I see that is feasable to do. I also thought about controlling the stdin of the process and pass the command .read into it but I was not sure wather this will work. You can try it but as I said not sure if it works.
schoetbi
Thanks, I tried running the script in one go but it didn't work. Then I read in the file and execute line by line, bingo! Thanks again.
Sunny Ho