-1
SELECT count(*) from BOOKS where BOOKS.TAG_ID like '%,1,%'

我想在 Objective-C 中执行这个查询。

 const char *sql = "Select count(*) from Documents WHERE DocumentTag LIKE '%i,?,%i'";
 sqlite3_stmt *sqlStatement;
 NSString *bindParam = [NSString stringWithFormat:@"%d", tagId];
if(sqlite3_bind_int(sqlStatement, 1, tagId)!= SQLITE_OK){
    NSLog(@"Problem binding search text param.");
}
else if(sqlite3_prepare_v2(database, sql, -1, &sqlStatement, NULL)==SQLITE_OK)
{
    sqlite3_bind_int(sqlStatement, 1, sqlite3_column_int(sqlStatement, 0));
    if(sqlite3_step(sqlStatement)==SQLITE_ROW)
    taskCount=sqlite3_column_int(sqlStatement,0);
    sqlite3_reset(sqlStatement);
    sqlite3_finalize(sqlStatement);

}
4

1 回答 1

1

在字符串文字中无法识别参数标记(否则,将无法?在字符串中使用字符)。

您必须LIKE从三个字符串、参数、前缀和后缀构造您的模式:

const char *sql = "Select count(*) from Documents"
                  " WHERE DocumentTag LIKE '%i,' || ? || ',%i'";
于 2013-05-02T08:52:29.390 回答