Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
Last active December 30, 2015 16:19
Show Gist options
  • Save ivan3bx/7853749 to your computer and use it in GitHub Desktop.
Save ivan3bx/7853749 to your computer and use it in GitHub Desktop.
Get the current schema out of a SQLite database..
- (NSString *)schemaFor:(NSString *)dbFile
{
sqlite3 *db;
NSString *query = @"select name, sql from sqlite_master where type = 'table'";
NSString *result;
if (sqlite3_open([dbFile UTF8String], &db) == SQLITE_OK) {
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, [query UTF8String], -1, &stmt, NULL) == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
result = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
}
}
sqlite3_finalize(stmt);
sqlite3_close(db);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment