FavoritesData.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // FavoritesData.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-4-25.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "FavoritesData.h"
  9. @implementation FavoritesData
  10. -(long) get_count
  11. {
  12. return self.pagedata.count;
  13. }
  14. - (id)init
  15. {
  16. self = [super init];
  17. if (self) {
  18. self.pagedata =[[NSMutableArray alloc]init];
  19. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  20. // NSString* required_ver=[objheader objectForKey:@"client_ver"] ;
  21. //
  22. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  23. // appDelegate.user = user;
  24. // appDelegate.password = password;
  25. sqlite3 *db =[ApexMobileDB get_db];
  26. NSString *quary = [NSString stringWithFormat:@"select _id,create_time,params,module_name,action,name from favorites where user='%@' order by _id desc",appDelegate.user];
  27. sqlite3_stmt *stmt;
  28. if (sqlite3_prepare_v2(db, [quary UTF8String], -1, &stmt, nil) == SQLITE_OK) {
  29. DebugLog(@"sql:%@",quary);
  30. while (sqlite3_step(stmt)==SQLITE_ROW)
  31. {
  32. // NSString *aname = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
  33. int _id = sqlite3_column_int(stmt, 0);
  34. // NSString* str_time = sqlite3
  35. NSString* create_time = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
  36. NSString* params =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 2)];
  37. NSString* module_name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 3)];
  38. NSString* action =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 4)];
  39. NSString* name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 5)];
  40. NSMutableDictionary * map = [[NSMutableDictionary alloc] init];
  41. [map setValue:[NSString stringWithFormat:@"%d",_id] forKey:@"_id"];
  42. [map setValue:[NSString stringWithFormat:create_time,create_time] forKey:@"create_time"];
  43. [map setValue:params forKey:@"params"];
  44. [map setValue:module_name forKey:@"module_name"];
  45. [map setValue:name forKey:@"name"];
  46. [map setValue:action forKey:@"action"];
  47. [self.pagedata addObject:map];
  48. }
  49. sqlite3_finalize(stmt);
  50. }
  51. //用完了一定记得关闭,释放内存
  52. sqlite3_close(db);
  53. }
  54. return self;
  55. }
  56. - (void)deleteAll:(void(^)(BOOL))complete {
  57. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  58. NSString *sql = [NSString stringWithFormat:@"delete from favorites where user='%@';",appDelegate.user];
  59. __weak typeof(self) weakSelf = self;
  60. [ApexMobileDB jk_excute:sql completion:^(BOOL success) {
  61. if (success) {
  62. [weakSelf.pagedata removeAllObjects];
  63. }
  64. if (complete) {
  65. complete(success);
  66. }
  67. }];
  68. }
  69. @end