0

Is it possible to read a .sqlite script with row insertions and updates in iOS? Or if you want to read sql statements from a file, you can only read the file line by line as if it were a regular text file? I need to make a large amount of row insertions in an already existing sqlite table I have, and I have all the insert statements in an .sql file. I've looking for a way to do this, but I was not able to find any for iOS.

Thanks!

AppsDev
  • 12,319
  • 23
  • 93
  • 186

1 Answers1

0

Your .sqlite script is just a text file so you can load it. You can read it in line by line but you can also read the whole script (depending on size) into an NSString (stringWithContentsOfFile:encoding:error:) and then use the contents however you want.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Thanks. Do you know where can I find an example of executing the `NSString` I get, assuming that it contains `sql` statements? – AppsDev Jul 31 '13 at 12:51
  • I have the statements in code as `const char*` and I use the `sqlite_prepare_v2` function with such `const char*` and a `sqlite3 stmt`. Should I read the lines of the file and supply them to the `sqlite_prepare_v2` function one by one, or is there any way to just run the whole script? – AppsDev Jul 31 '13 at 13:06