我终于想出了如何连接到我的数据库。我成功读取了查询的第一行,但是如何获得第二行?
if (sqlite3_prepare_v2(localDB,query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *st0 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
NSString *st1 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
NSString *st2 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)];
NSString *st3 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)];
NSString *st4 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 4)];
NSString *st5 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 5)];
NSLog(@"0: %@",st0);
NSLog(@"1: %@",st1);
NSLog(@"2: %@",st2);
NSLog(@"3: %@",st3);
NSLog(@"4: %@",st4);
NSLog(@"5: %@",st5);
}
else
{
NSLog(@"%s","Match not found");
}
sqlite3_finalize(statement);
}
else
{
NSLog(@"%s","Error on SQLITE_OK");
}
答案 0 :(得分:4)
使用while(sqlite3_step(statement) == SQLITE_ROW)
代替if (sqlite3_step(statement) == SQLITE_ROW)
,然后您就可以遍历每一行。