加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

用数组读取sqlite数据

发布时间:2020-12-12 19:59:43 所属栏目:百科 来源:网络整理
导读:- ( 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 strin

- (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);

}}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读