HistoryData.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // HistoryData.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-4-24.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "HistoryData.h"
  9. @implementation HistoryData
  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. ApexMobileAppDelegate *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,name from history 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* name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 4)];
  39. NSMutableDictionary * map = [[NSMutableDictionary alloc] init];
  40. [map setValue:[NSString stringWithFormat:@"%d",_id] forKey:@"_id"];
  41. [map setValue:[NSString stringWithFormat:create_time,create_time] forKey:@"create_time"];
  42. [map setValue:params forKey:@"params"];
  43. [map setValue:module_name forKey:@"module_name"];
  44. [map setValue:name forKey:@"name"];
  45. [self.pagedata addObject:map];
  46. }
  47. sqlite3_finalize(stmt);
  48. }
  49. //用完了一定记得关闭,释放内存
  50. sqlite3_close(db);
  51. }
  52. return self;
  53. }
  54. @end