我正在为 iOS 开发,我以前的数据库构建得非常糟糕。现在已经有 140 个密封但在我的更新中我创建了一个新数据库但我无法删除数据......我如何将数据从数据库 A 更改为数据库 B?我在 xCode 5 中使用 sqlite3
最佳答案
这是一个更改数据库表中的列的示例代码:
- (void)alterDB {
sqlite3_stmt *statement;
sqlite3_stmt *selectStmt;
const char *columnExists = "select callCount from lastCall";
//Alter the table ONLY IF column we want doesn't exist
if (sqlite3_prepare_v2(database, columnExists, -1, &selectStmt, NULL) != SQLITE_OK)
{
NSString *updateSQL = [NSString stringWithFormat:@"ALTER TABLE lastCall ADD COLUMN callCount INTEGER"];
const char *update_stmt = [updateSQL UTF8String];
sqlite3_prepare_v2(database, update_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE) {
NSLog(@"DATABASE ALTERED");
} else {
NSLog(@"error altering database");
}
}
}
我希望这能给你一个想法。
关于ios - 更改数据库数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19864150/