Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void) queryDatabaseWithSelectedDates: (sqlite3 *) db{
- NSMutableArray *rezultList = [[NSMutableArray alloc] init];
- sqlite3_stmt *select_statement;
- //if (insert_statement == nil) {
- static char *sql = "SELECT Employees.EmpID, Employees.FirstName, Employees.LastName, Presences.PresenceID, Presences.PrecenseState, Presences.WorkedHours, Presences.ExtraHours
- FROM Employees JOIN Presences ON Employees.EmpID = Presences.EmpID
- WHERE Presences.Date > ? AND Presences.Date < ?";
- if (sqlite3_prepare_v2(db, sql, -1, &select_statement, NULL) == SQLITE_OK) {
- sqlite3_bind_int(select_statement, 1, self.timestampStartReport);
- sqlite3_bind_int(select_statement, 2, self.timestampEndReport);
- while (sqlite3_step(select_statement) == SQLITE_ROW) {
- NSInteger empID = sqlite3_column_int(select_statement, 1);
- const char* firstnamec = (const char*)sqlite3_column_text(select_statement, 2);
- const char* lastnamec = (const char*)sqlite3_column_text(select_statement, 3);
- NSInteger presenceID = sqlite3_column_int(select_statement, 4);
- NSInteger presenceState = sqlite3_column_int(select_statement, 5);
- NSInteger presenceWorkedHours= sqlite3_column_int(select_statement, 6);
- NSInteger presenceExtraHours= sqlite3_column_int(select_statement, 7);
- NSString *firstName = nil;
- NSString *lastName = nil;
- /*Check if the values returned from database are <>null*/
- if(firstnamec){
- firstName = [NSString stringWithUTF8String:firstnamec];
- }
- if(lastNamec){
- lastName = [NSString stringWithUTF8String:lastnamec];
- }
- Employee *tempEmployee = [[Employee alloc]initWithDates:empID
- firstName:firstName
- lastName:lastName
- phone:nil
- adress:nil
- norma:nil
- socialID:nil
- observations:nil];
- Presence *tempPresence = [[Presence alloc] initWithDates:empID
- presenceID:presenceID
- date:nil
- presenceState:presenceState
- workedHours:presenceWorkedHours
- extraHours:presenceExtraHours];
- if ([tempEmployee isAlreadyInDatabase:db theSid:empID] == NO)
- {
- [rezultList addObject:tempEmployee];
- [tempEmployee addPresence:tempPresence];
- }
- else
- [tempEmployee addPresence:tempPresence];
- }
- }
- else
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DatabaseNotAvailable", @"") message:[NSString stringWithUTF8String:sqlite3_errmsg(db)]
- delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
- [alert show];
- [alert release];
- }
- sqlite3_finalize(select_statement);
- }
Add Comment
Please, Sign In to add comment