Guest User

Untitled

a guest
Jun 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. -(void) queryDatabaseWithSelectedDates: (sqlite3 *) db{
  2.  
  3. NSMutableArray *rezultList = [[NSMutableArray alloc] init];
  4.  
  5.  
  6. sqlite3_stmt *select_statement;
  7. //if (insert_statement == nil) {
  8. static char *sql = "SELECT Employees.EmpID, Employees.FirstName, Employees.LastName, Presences.PresenceID, Presences.PrecenseState, Presences.WorkedHours, Presences.ExtraHours
  9. FROM Employees JOIN Presences ON Employees.EmpID = Presences.EmpID
  10. WHERE Presences.Date > ? AND Presences.Date < ?";
  11. if (sqlite3_prepare_v2(db, sql, -1, &select_statement, NULL) == SQLITE_OK) {
  12. sqlite3_bind_int(select_statement, 1, self.timestampStartReport);
  13. sqlite3_bind_int(select_statement, 2, self.timestampEndReport);
  14.  
  15.  
  16.  
  17.  
  18. while (sqlite3_step(select_statement) == SQLITE_ROW) {
  19.  
  20. NSInteger empID = sqlite3_column_int(select_statement, 1);
  21. const char* firstnamec = (const char*)sqlite3_column_text(select_statement, 2);
  22. const char* lastnamec = (const char*)sqlite3_column_text(select_statement, 3);
  23. NSInteger presenceID = sqlite3_column_int(select_statement, 4);
  24. NSInteger presenceState = sqlite3_column_int(select_statement, 5);
  25. NSInteger presenceWorkedHours= sqlite3_column_int(select_statement, 6);
  26. NSInteger presenceExtraHours= sqlite3_column_int(select_statement, 7);
  27.  
  28.  
  29. NSString *firstName = nil;
  30. NSString *lastName = nil;
  31.  
  32. /*Check if the values returned from database are <>null*/
  33. if(firstnamec){
  34. firstName = [NSString stringWithUTF8String:firstnamec];
  35. }
  36. if(lastNamec){
  37. lastName = [NSString stringWithUTF8String:lastnamec];
  38. }
  39.  
  40.  
  41. Employee *tempEmployee = [[Employee alloc]initWithDates:empID
  42. firstName:firstName
  43. lastName:lastName
  44. phone:nil
  45. adress:nil
  46. norma:nil
  47. socialID:nil
  48. observations:nil];
  49.  
  50. Presence *tempPresence = [[Presence alloc] initWithDates:empID
  51. presenceID:presenceID
  52. date:nil
  53. presenceState:presenceState
  54. workedHours:presenceWorkedHours
  55. extraHours:presenceExtraHours];
  56.  
  57. if ([tempEmployee isAlreadyInDatabase:db theSid:empID] == NO)
  58. {
  59. [rezultList addObject:tempEmployee];
  60. [tempEmployee addPresence:tempPresence];
  61. }
  62. else
  63. [tempEmployee addPresence:tempPresence];
  64.  
  65.  
  66. }
  67. }
  68. else
  69. {
  70. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DatabaseNotAvailable", @"") message:[NSString stringWithUTF8String:sqlite3_errmsg(db)]
  71. delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
  72. [alert show];
  73. [alert release];
  74. }
  75. sqlite3_finalize(select_statement);
  76.  
  77. }
Add Comment
Please, Sign In to add comment