sqlite3_step(声明)。返回100

时间:2011-10-05 09:32:39

标签: iphone sqlite

我正在尝试访问sqlite数据库 sqlite3_step应该返回0 ??但它没有!!

if(sqlite3_open([DatabasePath UTF8String],&database)==SQLITE_OK){
    self.searchtext.text=DatabasePath ;

    const char *sql="select *from cars";
    sqlite3_stmt *selectstatment;


    if(sqlite3_prepare_v2(database,sql,-1,&selectstatment,Nil)==SQLITE_OK){
        self.searchtext.text=@" database prepared";

        while(sqlite3_step(selectstatment)==SQLITE_OK){
            // fetch the id
            SQLITETEST10000AppDelegate *carobject=[[SQLITETEST10000AppDelegate alloc] init ];
             carobject->primarykey=sqlite3_column_int(selectstatment, 0);
            //fetch the name
             carobject.carname =[NSString stringWithUTF8String:(char*)sqlite3_column_int(selectstatment, 1)];

            [appdelegate.Cars addObject:carobject];

            [carobject release];   
        }
    }else self.searchtext.text=@" database Not prepared";
}

1 个答案:

答案 0 :(得分:4)

您应该read the sqlite3 C API documentation (this page for sqlite3_step function)

sqlite3_step可以返回多个值,当一切正常时最常见的是SQLITE_ROW告诉它成功返回一行而SQLITE_DONE当它完成迭代后返回的所有行时查询。 sqlite3_step永远不会返回SQLITE_OK

值100(请参阅the result codes page in the doc too)对应SQLITE_ROW,因此这完全符合您的预期。