这是我的代码:
- (void) addOrder {
if(addStmt == nil) {
const char *sql = "insert into item(menuid,itemName,price,quantity,spiciness) Values(?, ?, ?, ?, ?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_int(addStmt, 1, [menuID integerValue]);
sqlite3_bind_text(addStmt, 2, [itemName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_double(addStmt, 3, price );
sqlite3_bind_int(addStmt, 4, [quantity integerValue]);
sqlite3_bind_text(addStmt, 5, [spiciness UTF8String],-1,SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
menuID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
}
我的menuID是NSdecimalNumber。在else部分
menuID = sqlite3_last_insert_rowid(database);
我收到了错误
“Implicit conversion of sqlite3_int64 to NsdecimalNumber is disallowed with ARC.
我怎么能删除这个错误?请帮助..
答案 0 :(得分:1)
正如你所说,menuID是NSDecimalNumber而不是它应该是,
menuID = [NSDecimalNumber numberWithInt:sqlite3_last_insert_rowid(database)];
答案 1 :(得分:1)
由于它似乎是一个64位的int,而iOS是一个32位系统,你可能想要使用:
menuID = [NSDecimalNumber numberWithLongLong:sqlite3_last_insert_rowid(database)];