Hi all,
I have to add programmatically two tables to a sqlite3 database.
Have you some useful links or examples of how I could do it?
Thanks in advance,
Fran
Hi all,
I have to add programmatically two tables to a sqlite3 database.
Have you some useful links or examples of how I could do it?
Thanks in advance,
Fran
Code:
-(void) createTableNamed:(NSString *) tableName withField1:(NSString *) field1 withField2:(NSString *) field2 {
char *err;
NSString *sql = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS '%@' ('%@' TEXT PRIMARY KEY, '%@' TEXT);", tableName, field1, field2];
if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
sqlite3_close(db);
NSAssert(0, @"Table failed to create.");
}
}
Here db is an object of type sqlite3
__________________ iOS Developerz
You Think, We Create...
The sqlite3_exec() interface is a convenience wrapper around sqlite3_prepare_v2(), sqlite3_step(), and sqlite3_finalize(), that allows an application to run multiple statements of SQL without having to use a lot of C code.