Does anyone know of an Objective-C library that will easily allow developers to parse a SQL file? I am building an iPhone application that contains a SQLite database and I am attempting to come with a system to upgrade a user's writable database. After reading a lot of the questions and answers on this site it appears that the best way to perform both DDL and DML operations is to keep a list of SQL files that will perform the necessary database upgrades. So now that I've decided that I am going to read a SQL file in the application bundle and then execute the individual SQL statements I need a way to parse the actual file into executable statements. From what I have read, there does not seem to be an existing library that will read a file line by line let alone parse SQL specific content. Does anyone know of one?
My current plan is to read the entire file into an NSString using:
NSString *fileContents = [NSString stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:&error];
From there I am going to parse out the statements by splitting the string on the semicolon using [NSScanner scanUpToString]
or [NSString componentsSeparatedByString]
. I keep telling myself that there has to be a better way to do this because by using this crude method, I am going to lose the ability to include comments in the scripts. Any suggestions?