Objective c 在Select查询中将变量替换为其值

Objective c 在Select查询中将变量替换为其值,objective-c,sql,ios,sqlite,Objective C,Sql,Ios,Sqlite,这是我的情况,我想在select查询中使用NSString变量: NSString *arrayThemeList=@"element1, element2, element3"; if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK) { NSString *querySQL = [NSString stringWithFormat: @"SELECT *

这是我的情况,我想在select查询中使用NSString变量:

NSString *arrayThemeList=@"element1, element2, element3";
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
    {
        NSString *querySQL = [NSString stringWithFormat: 
                              @"SELECT * from table1 where type IN ?"];

        const char *query_stmt = [querySQL UTF8String];


        if (sqlite3_prepare_v2(contactDB, 
                               query_stmt, -1, &statement, NULL) == SQLITE_OK)
        {
            sqlite3_bind_text(statement, 1, [arrayThemeList UTF8String], -1, SQLITE_TRANSIENT);

            while (sqlite3_step(statement) == SQLITE_ROW)
            {

               //Do the rest work...
显然,我想在bind语句的查询中使用arrayThemeList

然而,这似乎并没有得到想要的结果,我有什么做错了吗?
Thanx PREVICE:

in子句中的条目应括在括号内。尝试:

        NSString *querySQL = [NSString stringWithFormat: 
                          @"SELECT * from table1 where type IN ( ? )"];
此外,字符串需要封闭,因此将第一行更改为:

NSString *arrayThemeList=@"'element1', 'element2', 'element3'";
结果查询应为:

SELECT * from table1 where type IN ( 'element1', 'element2', 'element3' )

如果要将变量绑定到IN列表的某些部分,则需要在IN列表周围加上一些括号,并且必须为每个单独的值加上一个占位符问号:

SELECT * FROM table1 WHERE type IN (?, ?, ?);
然后绑定三个单独的值,每个占位符一个。在大多数SQL数据库管理系统中没有一种方法;我认为在SQLite中,将值列表绑定到单个占位符是不够的


如果只以单个字符串的形式获取数据,那么在准备语句之前必须格式化SQL,并且放弃了使用不同值重用准备好的语句的能力,因此您必须担心。此外,如果您处理的是字符串值,则需要将每个字符串用单引号括起来,并通过加倍的方式转义任何嵌入的单引号。

您好,谢谢您的回答:不幸的是,我还没有得到任何结果: