0
我已經編寫了用於插入具有外鍵值的數據的代碼,但它不在Sqlite3_open方法中。請幫幫我 。我沒有得到什麼問題?添加語句不適用於sqlite
- (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);
}
好吧讓我試試... – DeviPhone26