7. --SQLite 专属的条件查找

前端之家收集整理的这篇文章主要介绍了7. --SQLite 专属的条件查找前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//查询单个学生

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

猜你在找的Sqlite相关文章