0
更新文本保存到數據庫中,我有UITextView的寫筆記。寫完筆記後,點擊完成按鈕文本將保存到數據庫。當我添加一些更多的文本從舊文本繼續然後單擊完成按鈕它保存新的一行文本。如何在iOS的
表:
texts texts_id
Hi 1
Hi, How are u? 1
首先,我寫了喜文本,然後單擊完成。然後我從數據庫中查詢文字,並寫下你如何?但它保存了新的行?我需要用嗨替換第一排,你好嗎?可能嗎?
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
const char *sql = [[NSString stringWithFormat:@"SELECT textnotes FROM textnote where textnote = '%@','%@',",txtview.text,artID] cStringUsingEncoding:NSUTF8StringEncoding];
NSLog(@"sql is %s",sql);
BOOL favExist = false;
sqlite3_stmt *statement, *addStmt;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
// We "step" through the results - once for each row.
while (sqlite3_step(statement) == SQLITE_ROW) {
favExist = true;
}
}
if(!favExist){
const char *sqlInsert = [[NSString stringWithFormat:@"insert into textnote (textnotes,text_id) values ('%@','%@')", txtview.text,artID] cStringUsingEncoding:NSUTF8StringEncoding];
NSLog(@"sql insert is %s",sqlInsert);
// [catID release];
if(sqlite3_prepare_v2(database, sqlInsert, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
}