Hi,
I am trying to prepopulate my SQlite Table from a Text File - alltough it is compiling fine, no rows will be inserted:
NSLog(@"Insert Table for English");
char *errorMsg;
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath ] stringByAppendingPathComponent:@"english.sql"];
NSLog(@"DefaultPath: %@", defaultDBPath);
NSString *sql = [[[NSString alloc] initWithContentsOfFile:defaultDBPath
encoding:NSUTF8StringEncoding
error:NULL] autorelease];
if (sqlite3_exec(database,[sql UTF8String],NULL,NULL, &errorMsg) != SQLITE_OK) {
NSAssert1(0, @"Error loading update file: %s", errorMsg);
}
NSLog(@"I should have written something");
This is how my text file looks like:
BEGIN TRANSACTION;
INSERT INTO PARTNER(branche) VALUES('Choose music for the Ceremony');
COMMIT;
I create the Database here:
-(void)createDatabase {
NSUserDefaults *userSETTINGS = [NSUserDefaults standardUserDefaults];
NSLog(@"HUHU - schau ma mal: Database = %d", [userSETTINGS integerForKey:@"Database"]);
if ([userSETTINGS integerForKey:@"Database"] == 0) {
if (sqlite3_open([[self dataFilePath] UTF8String], &database) != SQLITE_OK) {
sqlite3_close(database);
NSAssert(0, @"Failed to open database");
}
char *errorMsg;
//sqlite3_stmt *statement;
NSString *createSQL = @"CREATE TABLE IF NOT EXISTS PARTNER (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, branche TEXT, company TEXT, name TEXT, phone TEXT, email TEXT, price INT, notes TEXT, done TEXT);";
if (sqlite3_exec(database, [createSQL UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK) {
sqlite3_close(database);
NSAssert1(0, @"Error createing table: %s", errorMsg);
}
NSUserDefaults *userSETTINGS = [NSUserDefaults standardUserDefaults];
[userSETTINGS setInteger:1 forKey:@"Database"];
NSLog(@"HUHU - schau ma mal: Database = %d", [userSETTINGS integerForKey:@"Database"]);
[self fillDatabase];
} else {
NSLog(@"Database wurde schon angelegt");
[self readDatabase];
}
}
The Log File tells my, that defaultDBPath is:
DefaultPath: /Users/sl/Library/Application Support/iPhone Simulator/User/Applications/0BE2EDC6-F070-43BE-9666-310257B495B9/WeddingPlanner.app/english.sql
What am I missing? The DB is correct, the Path is OK but nothing will be written...
Thanks for your answers, help, advice... :-)
BR,
Stefan