从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;
答案 0 :(得分:0)
sqlite3_prepare_v2
只准备第一个语句,你必须单独运行3个语句。
请参阅:http://www.sqlite.org/c3ref/prepare.html
如果pzTail不为NULL,则* pzTail指向zSql中第一个SQL语句结尾之后的第一个字节。这些例程只编译zSql中的第一个语句,因此* pzTail指向仍未编译的内容。