封装成DAO
@implementation SqlHelper
+(BOOL)InsertSql:(NSString *)sql paramet:(NSMutableDictionary *)parmet{
return [self Modifysql:sql parametDic:parmet];
}
+(BOOL)UpdateSql:(NSString *)sql paramet:(NSMutableDictionary *)parmet{
return [self Modifysql:sql parametDic:parmet];
}
+(BOOL)DeleteSql:(NSString *)sql paramet:(NSMutableDictionary *)parmet{
return [self Modifysql:sql parametDic:parmet];
}
+(void)QuerySql:(NSString *)sql paramet:(NSMutableDictionary *)parmet result:(NSMutableArray *)results{
PLSqliteDatabase *db=[[appGlobal InitGloab] DBHelper];//这个封装成一个单例
id<PLPreparedStatement> stmp=[db prepareStatement:sql];
[stmp bindParameterDictionary:parmet];
id<PLResultSet> result=[stmp executeQuery];
while ([result next]) {
person *p=[[person alloc] init];
p.name=[result stringForColumn:@"name"];
p.age=[result intForColumn:@"age"];
p.pid=[result intForColumn:@"id"];
[results addObject:p];
[p release];
}
}
+(BOOL)Modifysql:(NSString *)sql parametDic:(NSMutableDictionary *)parmet{
PLSqliteDatabase *db=[[appGlobal InitGloab] DBHelper];
id<PLPreparedStatement> stmp=[db prepareStatement:sql];
[stmp bindParameterDictionary:parmet];
if ([stmp executeUpdate]) {
return YES;
}
return NO;
}
@end
@interface person : NSObject
@property(nonatomic,assign)int pid;
@property(nonatomic,copy)NSString *name;
@property(nonatomic,assign)int age;
@end