IOS之数据库的查找,删除,添加,更新
2012-11-21 14:03:36 来源:WEB开发网核心提示:sqlite3 *db = [DB openDB];sqlite3_stmt *stmt = nil;int result = sqlite3_prepare_v2(db, [str UTF8String],-1 ,&stmt , nil);if (result == SQLITE_OK) {sqlite3_step(
sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;
int result = sqlite3_prepare_v2(db, [str UTF8String],-1 ,&stmt , nil);
if (result == SQLITE_OK)
{
sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
}
//根据ID删除信息
+(void)deleteByID:(int)ID
{
NSString *str = [NSString stringWithFormat:@"delete from classDB where ID = %d",ID];
sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;
int result = sqlite3_prepare_v2(db, [str UTF8String], -1, &stmt, nil);
if (result == SQLITE_OK)
{
sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
}
//更新
+(void)updataName:(NSString *)name phone:(NSString *)phone age:(int)age forID:(int)ID
{
NSString *str = [NSString stringWithFormat:@"update classDB set name = '%@',phone = '%@',age = %d where ID = %d",name,phone,age,ID];
sqlite3 *db = [DB openDB];
sqlite3_stmt *stmt = nil;
int result = sqlite3_prepare_v2(db, [str UTF8String], -1, &stmt, nil);
if (result == SQLITE_OK)
{
sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
}
@end
更多精彩
赞助商链接