作者:mobiledu2502894453 | 来源:互联网 | 2023-09-03 08:27
IOS 数据库插入;
sqlite3_stmt * stmt;
// 预编译SQL语句,stmt变量保存了预编译结果的指针
int result = sqlite3_prepare_v2(database,insertSQL, -1, &stmt, nil);
debugLog(@"RKDBHelper -> insertLeyyeUser:result:%i",result);
// 如果预编译成功
if (result == SQLITE_OK) {
sqlite3_bind_text(stmt, 3,[user.userNick UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 4,[user.password UTF8String], -1, NULL);
// 执行SQL语句
sqlite3_step(stmt);
sqlite3_finalize(stmt);
sqlite3_close(database);
return YES;
}
数据库查询操作:
sqlite3_stmt * stmt;
// 预编译SQL语句,stmt变量保存了预编译结果的指针
int result = sqlite3_prepare_v2(database,insertSQL, -1, &stmt, nil);
// 如果预编译成功
if (result == SQLITE_OK) {
sqlite3_bind_double(stmt, 1, article.score);
sqlite3_bind_text(stmt, 2,[article.title UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 3,[article.intro UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 4,[article.content UTF8String], -1, NULL);