//查询单个学生
-(Student *)selectStudentWithName:(NSString *)name
{
Student *student = nil;
//伴随指针
sqlite3_stmt *stmt = nil;
//准备查询语句
NSString *selectsql = [NSString stringWithFormat:@"select * from student where name = '%@'",name];
//查询
int result = sqlite3_prepare(db,selectsql.UTF8String,-1,&stmt,NULL);
if (sqlITE_OK == result) {
while (sqlITE_ROW == sqlite3_step(stmt)) {
student = [Student new];
student.number = sqlite3_column_int(stmt, 0);
student.name = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(stmt,1)];
student.age = sqlite3_column_int(stmt, 2);
student.gender = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(stmt,3)];
NSLog(@" %@",student);
}
}else
{
NSLog(@"查询失败");
}
//释放指针
sqlite3_finalize(stmt);
return student;
}
原文链接:https://www.f2er.com/sqlite/199297.html