我已经编写了这段代码来插入具有外键值的数据,但它不在 Sqlite3_open 方法中。请帮我 。我没有得到什么问题?
- (void)AddCashGame {
sqlite3_stmt *addStmt;
appDelegate = (XYZAppDelegate *)[UIApplication sharedApplication].delegate;
NSString *dbPath = [appDelegate.GetDocumentDirectory stringByAppendingPathComponent:@"PokerDatabase.sqlite"];
NSLog(@"Db path is %@",dbPath);
if (sqlite3_open([dbPath UTF8String], &database) ){
const char *sql="insert into CashGameCell (CashLocation,CashGames,CashBank,CashBuy,CashFood,CashNote,CashRebuyCount,CashRebuyTotal,CashTokes,CashPlayer,CashProfileid) values (?,?,?,?,?,?,?,?,?,?,?)";
if (sqlite3_prepare(database, sql, -1, &addStmt, NULL)!= SQLITE_OK) {
NSLog(@"Error while creating database %s",sqlite3_errmsg(database));
}
sqlite3_bind_text(addStmt, 1, [CashLocation UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 2, [CashGames UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 3, [CashBank UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 4, [CashBuy UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 5, [CashFood UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 6, [CashNote UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 7, [CashRebuyCount UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 8, [CashRebuyTotal UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 9, [CashTokes UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 10, [CashPlayer UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(addStmt, 11, CashProfileid);
}
if (SQLITE_DONE!= sqlite3_step(addStmt)) {
NSLog(@"Error while inserting");
}
else Cashid = sqlite3_last_insert_rowid(database);
NSLog(@"cash id in profile model %d",Cashid);
sqlite3_finalize(addStmt);
sqlite3_close(database);
}