我想要使用此代码插入数据库上的一些数据:IPhone发展 - sqlite3_bind_int不工作
-(void)insertLocationOnDatabase:(LocationType *)aLocation {
sqlite3_stmt *stmt;
int location = [aLocation.locationID intValue];
NSLog(@"Location ID: %i", location);
const char *sql = "insert into tbl_location values (?,?,?,?)";
if (sqlite3_prepare_v2(database, sql, -1, &stmt, NULL) == SQLITE_OK) {
sqlite3_bind_int(stmt, 0, location);
sqlite3_bind_text(stmt, 1, [aLocation.Description UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, [aLocation.isActive UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 3, [aLocation.sequenceOrder UTF8String], -1, SQLITE_TRANSIENT);
if (sqlite3_step(stmt) == SQLITE_DONE) {
NSLog(@"Location %@ inserted on database",aLocation.Description);
}
else {
NSLog(@"Error on step: %i",sqlite3_errcode(database));
}
}
else {
NSLog(@"Error on prepare: %i",sqlite3_errcode(database));
}
}
问题上一行:
sqlite3_bind_int(stmt, 0, location);
没有这条线和改变sql,代码工作正常,但是当我把这条线回来,我得到这个错误:
2010-09-17 10:24:01.032 StockControl[944:207] Error on step: 20
来自sqlite3.h:
#define SQLITE_MISMATCH 20 /* Data type mismatch */
有人知道我的错误在哪里?
问候, 克劳迪奥
完美,谢谢:) – Claudio 2010-09-17 00:38:54