Last active
December 30, 2015 16:19
-
-
Save ivan3bx/7853749 to your computer and use it in GitHub Desktop.
Get the current schema out of a SQLite database..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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