I ve completely given up on this, so if a moderator happens to come by, deleting would be great.
It doesn t hurt to leave this question up, but CoreData is so much nicer, you know?
我有一个处理表格内容的qlite数据库。 它是巨大的,也是一切的(比我所探讨的其他选择更容易),但我对 in忙。 我第一次在发射电 app后拿起一个物品, in的田地是空的。 重新入场工作罚款可节省费用并在桌上出现,但下一个胎盘(不重开 app)将第二个项目与第一个项目挂钩。
i.e., A(1) resets to A(0). 我将其固定下来(A(1)),但B(2)在我装上ed子后即成为B(1)。 之后(B(2))或(B(1))C(3)与B(#)相同。
我仍然可以列举造成这种情况的原因。 改用插头(编辑数据库一栏和每个相关档案)肯定会奏效,但把大量不必要的工作推向更慢和更容易中断的工作。
编辑:
CREATE TABLE"items" ("id” INTERT PRIMaire KEYAUTOINCREMENT NOT NUL, “name” VARCHAR, “need” INTERT DEFAULT 0, “notes” TEXT
- (void)updateItemAtIndexPath:(NSIndexPath *)path {
Item *i = (Item *)[items objectAtIndex:path.row];
int ret;
const char *sql = "update items set name = ?, need = ?, notes = ? where id = ?;";
if (!updStmt) { // build update statement
if ((ret = sqlite3_prepare_v2(database, sql, -1, &updStmt, NULL)) != SQLITE_OK) {
NSAssert1(0, @"Error building statement to update items [%s]", sqlite3_errmsg(database));
}
}
// bind values to statement
NSString *s = i.name;
if (s == NULL) s = @"";
sqlite3_bind_text(updStmt, 1, [s UTF8String], -1, SQLITE_TRANSIENT);
NSInteger n = i.need;
sqlite3_bind_int(updStmt, 2, n);
s = i.notes;
if (s == NULL) s = @"";
sqlite3_bind_text(updStmt, 3, [s UTF8String], -1, SQLITE_TRANSIENT);
n = i.itemid;
sqlite3_bind_int(updStmt, 4, n);
// now execute sql statement
if (sqlite3_step(updStmt) != SQLITE_DONE) {
NSAssert1(0, @"Error updating values [%s]", sqlite3_errmsg(database));
}
// now reset bound statement to original state
sqlite3_reset(updStmt);
}
- (void)insertItem:(Item *)item {
int ret;
const char *sql = "insert into items (name, need, notes) values (?, ?, ?);";
if (!insStmt) { // first insert - build statement
if ((ret = sqlite3_prepare_v2(database, sql, -1, &insStmt, NULL)) != SQLITE_OK) {
NSAssert1(0, @"Error building statement to insert item [%s]", sqlite3_errmsg(database));
}
}
// bind values
NSString *s = item.name;
if (s == NULL) s = @"";
sqlite3_bind_text(insStmt, 1, [s UTF8String], -1, SQLITE_TRANSIENT);
NSInteger n = item.need;
sqlite3_bind_int(insStmt, 2, n);
s = item.notes;
if (s == NULL) s = @"";
sqlite3_bind_text(insStmt, 3, [s UTF8String], -1, SQLITE_TRANSIENT);
// execute sql statement
if (sqlite3_step(insStmt) != SQLITE_DONE) {
NSAssert1(0, @"Error inserting item [%s]", sqlite3_errmsg(database));
}
// reset bound statement to original state
sqlite3_reset(insStmt);
[self readItems]; // refresh array
}