sqlite is able to create in-memory database, but is it possible done in iPhone?
This is the document state that in sqlite
http://www.sqlite.org/inmemorydb.html
I tried, but fail. It successful create the database, but fail to create table.
Below is my code:
-(BOOL) open{
NSString *path = @"";
if(sqlite3_open([path UTF8String], &database_) == SQLITE_OK) {
//bFirstCreate_ = YES;
NSLog(@"open == YES");
[self createChannelsTable:database_];
return YES;
} else {
sqlite3_close(database_);
NSLog(@"Error: open database file.");
return NO;
}
return NO;
}
- (BOOL) createChannelsTable:(sqlite3*)db{
NSString *comment = [[NSString alloc] init];
comment = @"CREATE TABLE Temp(Name text, Address text}";
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(db, [comment UTF8String], -1, &statement, nil) != SQLITE_OK) {
NSLog(@"Error: failed to prepare statement:create channels table");
return NO;
}
int success = sqlite3_step(statement);
sqlite3_finalize(statement);
if ( success != SQLITE_DONE) {
NSLog(@"Error: failed to dehydrate:CREATE TABLE channels");
return NO;
}
NSLog(@"Create table 'channels' successed.");
return YES;
}
Are you possibly missing a semicolon in your SQL command string and wrong ending ‘}’ instead of ‘)’ ?
Needs a semicolon after “Address text}” so it becomes:
I think you also go a memory leak when you create the NSString “comment”. You init it then you told the comment pointer to store another string when you used the assign statement.
You can do those two step in 1 like so: