iOS使用sqlite3数据库select数据

2016-12-14  本文已影响0人  Al0nezzz

if ([self OpenDB])

{

NSString *strsql;

strsql= [NSString stringWithFormat:@"SELECT COUNT(*) from NewsInfo where IsView = 0"];

const char *sqlStatement = [strsql cStringUsingEncoding:NSUTF8StringEncoding];

sqlite3_stmt *statement = nil;

if(sqlite3_prepare_v2(self.db, sqlStatement, -1, &statement, NULL) == SQLITE_OK)

{

while(sqlite3_step(statement) == SQLITE_ROW)

{

NoReadCount = (int)sqlite3_column_int(statement, 0);

}

}

//        sqlite3_finalize(statement);

}

return NoReadCount;

亮点在抽取结果一定要while循环出来,否则程序崩溃

上一篇 下一篇

猜你喜欢

热点阅读