【发布时间】:2013-11-19 14:49:17
【问题描述】:
我想像 Android 一样逐行更新我的数据库 sqlite3,并使用索引来更新特定行。我该如何使用它?
-(void) updateBddWithData:(Data*) data{
sqlite3 *databaseOK=self.database;
if(sqlite3_open([self.databasePath UTF8String], &databaseOK) == SQLITE_OK) {
NSString* updateIntoBdd = [NSString stringWithFormat:@"UPDATE ART_TABLE SET ida = '%@' ,title = '%@' ,chapo = '%@' ,link = '%@' ,linkimg = '%@' ,pubdate = '%@' ,creator = '%@' ,description = '%@' ",data.ide,data.title,data.chapo,data.link,data.linkImg,data.pubDate,data.creator,data.description];
sqlite3_stmt* statement = NULL;
int returnValue = (sqlite3_prepare_v2(databaseOK, [updateIntoBdd UTF8String], -1, &statement, NULL));
if(returnValue == SQLITE_OK){
if(sqlite3_step(statement) == SQLITE_DONE){
// What can I do ?
}
}
sqlite3_finalize(statement);
sqlite3_close(databaseOK);
}
}
当我调用我的方法 Update(object) 时,我只想用我的参数对象更新一个索引行。
感谢提前
【问题讨论】:
-
为 SQLITE 使用一些库,例如github.com/ogres/SQLiteDatabase-class-for-iOS-Objective-C
-
没有库就不行?
-
是的,这是可能的,但你必须编写至少时间倍于没有库的代码,你应该首先选择行,然后 forech 行更新它,你应该处理类型/列...等等,使用库,您只需选择并编写另一个更新查询,所有其他(sqlite)内容将由库管理
标签: ios sqlite sql-update