用数组读取sqlite数据

前端之家收集整理的这篇文章主要介绍了用数组读取sqlite数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

- (IBAction)load:(id)sender {

sqlite3_stmt *statement;

NSString *databasePath=[self databasePath];

const char *dbpath = [databasePath UTF8String];

if (sqlite3_open(dbpath,&db)==sqlITE_OK) {

NSString *querysql = [NSString stringWithFormat:@"SELECT classname,name from info where num=\"%@\"",num.text]; //================这里就实现了用号码查询,其他的可以另外实现

const char *querystatement = [querysql UTF8String];

if (sqlite3_prepare_v2(db,querystatement,-1,&statement,NULL)==sqlITE_OK) {

if (sqlite3_step(statement)==sqlITE_ROW) {

/*

//做个小测试(原来版本)

NSString *classnameField = [[NSString alloc] initWithUTF8String:(const char *)sqlite3_column_text(statement,0)];

NSString *nameField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,1)];

classname.text = classnameField;

name.text = nameField;

*/

//=======测试部分=====================

NSMutableArray *such =[[NSMutableArray alloc]initWithCapacity:30];

for (int i=0; i<2; i++) {

NSString *tab=[[NSString alloc] initWithUTF8String:(const char *)sqlite3_column_text(statement,i)];

[such addObject:tab];

}

classname.text=[such objectAtIndex:0];

name.text=[such objectAtIndex:1];

//=======================================

//status.text = @"find~~~";

}

sqlite3_finalize(statement);

}

sqlite3_close(db);

}}

原文链接:https://www.f2er.com/sqlite/200405.html

猜你在找的Sqlite相关文章