すべてがうまくいくように見えますが、prepare_v2 は SQLITE_OK を取得しません
SQL命令は非常に基本的なものです.sqliteマネージャーにコピーして貼り付けると、問題なく挿入されます
私が欠けているものはありますか?
//from view controller
- (void)viewDidLoad
{
[super viewDidLoad];
DBConnection* dbCon = [DBConnection alloc];
[dbCon init];
[dbCon InsertDataRollNo:@"888"];
}
-(id)init
{
//[super init];
DBName = @"FoodDB2.sqlite";
NSArray* documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDir = [documentsPath objectAtIndex:0];
DBPath = [documentsDir stringByAppendingPathComponent:DBName];
return self;
}
-(void)InsertDataRollNo:(NSString*)theName
{
[self CheckAndCreateDB];
sqlite3* database;
if(sqlite3_open([DBPath UTF8String], &database)== SQLITE_OK)
{
NSString* statement;
sqlite3_stmt* compliedStatement;
//statement = [[NSString alloc]initWithFormat:@"insert into Category(TheName)values('%d')",@"epa"];
statement = @"insert into Category(TheName)values('aaa')";
const char* sqlStatement = [statement UTF8String];
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compliedStatement, NULL) == SQLITE_OK)
{
if(SQLITE_DONE!=sqlite3_step(compliedStatement))
{
NSAssert1(0,@"Error by inserting '%s' ", sqlite3_errmsg(database));
}
else
{
NSAssert1(0,@"cool '%s' ", @"ope");
}
}
sqlite3_finalize(compliedStatement);
}
sqlite3_close(database);
}
-(void)CheckAndCreateDB
{
BOOL success;
NSFileManager* fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:DBPath];
if(success) return;
NSString* databasePathFromApp = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:DBName];
[fileManager copyItemAtPath:databasePathFromApp toPath:DBPath error:nil];
//[fileManager release];
}