1

我正在从 xcode 运行以下查询。但是,它没有返回任何结果。我很确定它应该返回结果,并且可以通过从 sqlite 浏览器运行相同的查询来确认相同的结果。然而,在 xcode 中, sqlite3_step 返回代码 101。我在这里做错了什么?

    NSMutableArray *pages = [[NSMutableArray alloc] init];

    char *query = " \
    drop table if exists tempT; \
    \
    create temporary table tempT \
    as \
    select \
    Page \
    from \
    ( \
     select 1 as Sort, 'Home' as Page \
     union \
     select 2 as Sort, 'Research' as Page \
     union \
     select distinct 3 as Sort, Category as Page from Researches \
     union \
     select 4 as Sort, 'Drafts' as Page \
     union \
     select 5 as Sort, 'Outbox' as Page \
     union \
     select 6 as Sort, 'Download' as Page \
     union \
     select 7 as Sort, 'Settings' as Page \
     union \
     select 8 as Sort, 'Deleted' as Page \
     ) as Sub \
    ORDER BY Sort, Page \
    ; \
     \
    select Page from tempT order by rowid \
    ";
    sqlite3_stmt *stmt;
    if (sqlite3_prepare_v2(database, query, -1, &stmt, nil) == SQLITE_OK)
    {
        while (sqlite3_step(stmt) == SQLITE_ROW)
        {
            [pages addObject: [NSString stringWithUTF8String: (char *)sqlite3_column_text(stmt, 0)]];
        }

        sqlite3_finalize(stmt);
    }

    return pages;
4

1 回答 1

0

sqlite3_prepare_v2只准备第一条语句,您必须分别运行 3 条语句。

见:http ://www.sqlite.org/c3ref/prepare.html

如果 pzTail 不为 NULL,则 *pzTail 指向 zSql 中第一个 SQL 语句末尾之后的第一个字节。这些例程只编译 zSql 中的第一条语句,因此 *pzTail 指向未编译的内容。

于 2012-12-22T02:41:14.830 回答