我的Iphone应用程序上有一个sqlite数据库。该数据库有一个名为“Students”的表 它有10行数据,密钥从1到11.但我想测试目标c编码是否在表上存在值为“3”的主键。
答案 0 :(得分:1)
运行select查询,如果它没有返回记录,则该记录不存在。
答案 1 :(得分:1)
您需要对其运行选择查询。有关如何执行此操作的深入信息是here。
基本步骤是:
代码看起来像这样
// Database already opened
// All error checking omitted because I am lazy
sqlite3_stmt statement;
// Replace columns below with the names of your actual columns
// and key with the name of the primary key column
errorResult = sqlite3_prepare_v2(dbConnection,
"select columns from students where key = ?",
-1,
&statement,
NULL);
// error check and handle any
errorResult = sqlite3_bind_int(statement, 1, 3); // Put 3 in place of first question mark
// error check and handle any
while ((errorResult = sqlite3_step(statement) == SQLITE_ROW)
{
// Use sqlite3 column functions to get data
// http://www.sqlite.org/c3ref/column_blob.html
}
// error check and handle any
errorCheck = sqlite3_finalize(statement);
// error check and handle any