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