Manos Chorianopoulos

handle db open

...@@ -4991,6 +4991,20 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) ...@@ -4991,6 +4991,20 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
4991 // [self initDBIfNeeded]; 4991 // [self initDBIfNeeded];
4992 // [self restore]; 4992 // [self restore];
4993 4993
4994 +
4995 + BOOL dbOpened = NO;
4996 + @try {
4997 + @synchronized (_DatabaseLock) {
4998 + dbOpened = [_db open];
4999 + }
5000 + }
5001 + @catch (NSException *exception) {
5002 + NSLog(@"Open db error: %@", exception.reason);
5003 + }
5004 + @finally {
5005 +// NSLog(@"Finally condition");
5006 + }
5007 +
4994 BOOL tableExist = NO; 5008 BOOL tableExist = NO;
4995 @try { 5009 @try {
4996 @synchronized (_DatabaseLock) { 5010 @synchronized (_DatabaseLock) {
...@@ -5007,7 +5021,7 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) ...@@ -5007,7 +5021,7 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
5007 time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; 5021 time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
5008 // NSString *accessToken = [NSString alloc]; 5022 // NSString *accessToken = [NSString alloc];
5009 NSString *accessToken = @""; 5023 NSString *accessToken = @"";
5010 - if (([_db open] == YES) && (tableExist == YES)) { 5024 + if ((dbOpened == YES) && (tableExist == YES)) {
5011 // FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; 5025 // FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
5012 // while ([accessTokenSet next]) { 5026 // while ([accessTokenSet next]) {
5013 // accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; 5027 // accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
...@@ -5165,6 +5179,19 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) ...@@ -5165,6 +5179,19 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
5165 // [self initDBIfNeeded]; 5179 // [self initDBIfNeeded];
5166 // [self restore]; 5180 // [self restore];
5167 5181
5182 + BOOL dbOpened = NO;
5183 + @try {
5184 + @synchronized (_DatabaseLock) {
5185 + dbOpened = [_db open];
5186 + }
5187 + }
5188 + @catch (NSException *exception) {
5189 + NSLog(@"Open db error: %@", exception.reason);
5190 + }
5191 + @finally {
5192 +// NSLog(@"Finally condition");
5193 + }
5194 +
5168 BOOL tableExist = NO; 5195 BOOL tableExist = NO;
5169 @try { 5196 @try {
5170 @synchronized (_DatabaseLock) { 5197 @synchronized (_DatabaseLock) {
...@@ -5181,7 +5208,7 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) ...@@ -5181,7 +5208,7 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
5181 time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; 5208 time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
5182 // NSString *accessToken = [NSString alloc]; 5209 // NSString *accessToken = [NSString alloc];
5183 NSString *accessToken = @""; 5210 NSString *accessToken = @"";
5184 - if (([_db open] == YES) && (tableExist == YES)) { 5211 + if ((dbOpened == YES) && (tableExist == YES)) {
5185 @try { 5212 @try {
5186 @synchronized (_DatabaseLock) { 5213 @synchronized (_DatabaseLock) {
5187 FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; 5214 FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
......