English 中文(简体)
在一个选择性的问询中按其价值重置一个变量
原标题:Replacing a variable by its value in a Select query

我的情况是这样,即在选择的询问中,我想使用国家抽样变量:

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...

很显然,我想将arrayThemeList输入到bind的查询中。

However, this seems not to be giving the wanted result, is there anything i am doing wrong? Thanx in advance:)

问题回答

IN条款的条目应当放在括号内。 Try:

        NSString *querySQL = [NSString stringWithFormat: 
                          @"SELECT * from table1 where type IN ( ? )"];

此外,你的指示必须附上,这样,第一行即改为:

NSString *arrayThemeList=@" element1 ,  element2 ,  element3 ";

由此引起的问题是:

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

如果您对某个国家名单的某些部分具有约束性变数,则您需要列入本国名单的一些括号,而且您必须拥有一个单独的持有人(问号):

SELECT * FROM table1 WHERE type IN (?, ?, ?);

之后,对三个不同的价值即一个固定持有人具有约束力。 没有什么办法(在大多数的房舍管理处;我认为也不在证券交易所)把价值清单约束给单一地点持有人。

如果你只拿到数据作为单体,那么,在你准备发言之前,你将不得不对数据进行编排,而你则放弃了用不同价值重复编制的声明的能力,并且你不得不担心SQL Injection。 此外,如果你处理扼杀性价值,你需要把每一条插在单项引用中(和越狱——一翻一番——任何嵌入的单一引文)。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签