IOS之数据库的查找,删除,添加,更新(3)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-22 14:54 点击:次
sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;
int result = sqlite3_prepare_v2(db, "select count(ID) from classDB", -1, &stmt, nil);
if (result == SQLITE_OK)
{
int count = 0;
if (sqlite3_step(stmt))
{
count = sqlite3_column_int(stmt, 0);
}
sqlite3_finalize(stmt);
return count;
}
else
{
sqlite3_finalize(stmt);
return 0;
}
}
+(Person *)findByID:(int)ID
{
sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;
Person *p = nil;
int result = sqlite3_prepare_v2(db, "select * from classDB where ID = ?", -1, &stmt, nil);
if (result == SQLITE_OK)
{
sqlite3_bind_int(stmt, 1, ID);
if (sqlite3_step(stmt))
{
int ID = sqlite3_column_int(stmt, 0);
const unsigned char *name = sqlite3_column_text(stmt, 1);
const unsigned char *phone = sqlite3_column_text(stmt, 2);
int age = sqlite3_column_int(stmt, 3);
p = [[Person alloc]initWithName:[NSString stringWithUTF8String:(const char *)name] phone:[NSString stringWithUTF8String:(const char *)phone] age:age ID:ID];
}
}
sqlite3_finalize(stmt);
return [p autorelease];
}
+(NSMutableArray *)findByname:(NSString *)name
{
sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>