ios中Pldatabase的用法(4)
2013-07-19 16:49 甘超波 阅读(323) 评论(0) 编辑 收藏 举报封装成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
目前我正在专注NLP,请立刻加微信/QQ号 546611623, 免费送你原创《NLP高级执行师》高清视频