Showing
1 changed file
with
256 additions
and
16 deletions
... | @@ -703,9 +703,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -703,9 +703,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
703 | [self createDBIfNeeded]; | 703 | [self createDBIfNeeded]; |
704 | [self initDBIfNeeded]; | 704 | [self initDBIfNeeded]; |
705 | [self restore]; | 705 | [self restore]; |
706 | + | ||
707 | + BOOL tableExist = NO; | ||
708 | + @try { | ||
709 | + @synchronized (_DatabaseLock) { | ||
710 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
711 | + } | ||
712 | + } | ||
713 | + @catch (NSException *exception) { | ||
714 | + NSLog(@"tableExists error: %@", exception.reason); | ||
715 | + } | ||
716 | + @finally { | ||
717 | +// NSLog(@"Finally condition"); | ||
718 | + } | ||
706 | // NSString *accessToken = [NSString alloc]; | 719 | // NSString *accessToken = [NSString alloc]; |
707 | NSString *accessToken = @""; | 720 | NSString *accessToken = @""; |
708 | - if ([_db tableExists:@"requestVariables"] == YES) { | 721 | + if (tableExist == YES) { |
709 | @try { | 722 | @try { |
710 | @synchronized (_DatabaseLock) { | 723 | @synchronized (_DatabaseLock) { |
711 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 724 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; |
... | @@ -732,9 +745,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -732,9 +745,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
732 | }; | 745 | }; |
733 | 746 | ||
734 | - (NSString*)getRefreshToken { | 747 | - (NSString*)getRefreshToken { |
748 | + | ||
749 | + BOOL tableExist = NO; | ||
750 | + @try { | ||
751 | + @synchronized (_DatabaseLock) { | ||
752 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
753 | + } | ||
754 | + } | ||
755 | + @catch (NSException *exception) { | ||
756 | + NSLog(@"tableExists error: %@", exception.reason); | ||
757 | + } | ||
758 | + @finally { | ||
759 | +// NSLog(@"Finally condition"); | ||
760 | + } | ||
735 | // NSString *refreshToken = [NSString alloc]; | 761 | // NSString *refreshToken = [NSString alloc]; |
736 | NSString *refreshToken = @""; | 762 | NSString *refreshToken = @""; |
737 | - if ([_db tableExists:@"requestVariables"] == YES) { | 763 | + if (tableExist == YES) { |
738 | @try { | 764 | @try { |
739 | @synchronized (_DatabaseLock) { | 765 | @synchronized (_DatabaseLock) { |
740 | FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | 766 | FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; |
... | @@ -761,9 +787,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -761,9 +787,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
761 | } | 787 | } |
762 | 788 | ||
763 | - (NSString*)getClientId { | 789 | - (NSString*)getClientId { |
790 | + | ||
791 | + BOOL tableExist = NO; | ||
792 | + @try { | ||
793 | + @synchronized (_DatabaseLock) { | ||
794 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
795 | + } | ||
796 | + } | ||
797 | + @catch (NSException *exception) { | ||
798 | + NSLog(@"tableExists error: %@", exception.reason); | ||
799 | + } | ||
800 | + @finally { | ||
801 | +// NSLog(@"Finally condition"); | ||
802 | + } | ||
764 | // NSString *clientId = [NSString alloc]; | 803 | // NSString *clientId = [NSString alloc]; |
765 | NSString *clientId = @""; | 804 | NSString *clientId = @""; |
766 | - if ([_db tableExists:@"requestVariables"] == YES) { | 805 | + if (tableExist == YES) { |
767 | @try { | 806 | @try { |
768 | @synchronized (_DatabaseLock) { | 807 | @synchronized (_DatabaseLock) { |
769 | FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | 808 | FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; |
... | @@ -790,9 +829,23 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -790,9 +829,23 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
790 | } | 829 | } |
791 | 830 | ||
792 | - (NSString*)getClientSecret { | 831 | - (NSString*)getClientSecret { |
832 | + | ||
833 | + BOOL tableExist = NO; | ||
834 | + @try { | ||
835 | + @synchronized (_DatabaseLock) { | ||
836 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
837 | + } | ||
838 | + } | ||
839 | + @catch (NSException *exception) { | ||
840 | + NSLog(@"tableExists error: %@", exception.reason); | ||
841 | + } | ||
842 | + @finally { | ||
843 | +// NSLog(@"Finally condition"); | ||
844 | + } | ||
845 | + | ||
793 | // NSString *clientSecret = [NSString alloc]; | 846 | // NSString *clientSecret = [NSString alloc]; |
794 | NSString *clientSecret = @""; | 847 | NSString *clientSecret = @""; |
795 | - if ([_db tableExists:@"requestVariables"] == YES) { | 848 | + if (tableExist == YES) { |
796 | @try { | 849 | @try { |
797 | @synchronized (_DatabaseLock) { | 850 | @synchronized (_DatabaseLock) { |
798 | FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | 851 | FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; |
... | @@ -964,7 +1017,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -964,7 +1017,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
964 | @synchronized (_DatabaseLock) { | 1017 | @synchronized (_DatabaseLock) { |
965 | [_db executeUpdate:@"DROP TABLE requestVariables"]; | 1018 | [_db executeUpdate:@"DROP TABLE requestVariables"]; |
966 | } | 1019 | } |
967 | - if ([_db tableExists:@"requestVariables"] == NO) { | 1020 | + |
1021 | + BOOL tableExist = NO; | ||
1022 | + @try { | ||
1023 | + @synchronized (_DatabaseLock) { | ||
1024 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1025 | + } | ||
1026 | + } | ||
1027 | + @catch (NSException *exception) { | ||
1028 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1029 | + } | ||
1030 | + @finally { | ||
1031 | + // NSLog(@"Finally condition"); | ||
1032 | + } | ||
1033 | + | ||
1034 | + if (tableExist == NO) { | ||
968 | @synchronized (_DatabaseLock) { | 1035 | @synchronized (_DatabaseLock) { |
969 | [_db executeUpdate:@"CREATE TABLE requestVariables (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, client_id INTEGER, client_secret VARCHAR(255), access_token VARCHAR(255), refresh_token VARCHAR(255))"]; | 1036 | [_db executeUpdate:@"CREATE TABLE requestVariables (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, client_id INTEGER, client_secret VARCHAR(255), access_token VARCHAR(255), refresh_token VARCHAR(255))"]; |
970 | WL_FMDBLogError | 1037 | WL_FMDBLogError |
... | @@ -1055,7 +1122,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1055,7 +1122,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1055 | @synchronized (_DatabaseLock) { | 1122 | @synchronized (_DatabaseLock) { |
1056 | [_db executeUpdate:@"DROP TABLE requestVariables"]; | 1123 | [_db executeUpdate:@"DROP TABLE requestVariables"]; |
1057 | } | 1124 | } |
1058 | - if ([_db tableExists:@"requestVariables"] == NO) { | 1125 | + |
1126 | + BOOL tableExist = NO; | ||
1127 | + @try { | ||
1128 | + @synchronized (_DatabaseLock) { | ||
1129 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1130 | + } | ||
1131 | + } | ||
1132 | + @catch (NSException *exception) { | ||
1133 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1134 | + } | ||
1135 | + @finally { | ||
1136 | + // NSLog(@"Finally condition"); | ||
1137 | + } | ||
1138 | + | ||
1139 | + if (tableExist == NO) { | ||
1059 | @synchronized (_DatabaseLock) { | 1140 | @synchronized (_DatabaseLock) { |
1060 | [_db executeUpdate:@"CREATE TABLE requestVariables (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, client_id INTEGER, client_secret VARCHAR(255), access_token VARCHAR(255), refresh_token VARCHAR(255))"]; | 1141 | [_db executeUpdate:@"CREATE TABLE requestVariables (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, client_id INTEGER, client_secret VARCHAR(255), access_token VARCHAR(255), refresh_token VARCHAR(255))"]; |
1061 | WL_FMDBLogError | 1142 | WL_FMDBLogError |
... | @@ -1158,7 +1239,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1158,7 +1239,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1158 | 1239 | ||
1159 | - (void)updateRefreshTokenW:(NSString*)access_token :(NSString*)refresh_token | 1240 | - (void)updateRefreshTokenW:(NSString*)access_token :(NSString*)refresh_token |
1160 | { | 1241 | { |
1161 | - if ([_db tableExists:@"requestVariables"] == YES) { | 1242 | + |
1243 | + BOOL tableExist = NO; | ||
1244 | + @try { | ||
1245 | + @synchronized (_DatabaseLock) { | ||
1246 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1247 | + } | ||
1248 | + } | ||
1249 | + @catch (NSException *exception) { | ||
1250 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1251 | + } | ||
1252 | + @finally { | ||
1253 | +// NSLog(@"Finally condition"); | ||
1254 | + } | ||
1255 | + | ||
1256 | + if (tableExist == YES) { | ||
1162 | @synchronized (_DatabaseLock) { | 1257 | @synchronized (_DatabaseLock) { |
1163 | [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", access_token, refresh_token]; | 1258 | [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", access_token, refresh_token]; |
1164 | } | 1259 | } |
... | @@ -1167,7 +1262,24 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1167,7 +1262,24 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1167 | 1262 | ||
1168 | - (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1263 | - (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
1169 | { | 1264 | { |
1170 | - if ([_db tableExists:@"requestVariables"] == YES) { | 1265 | + BOOL tableExist = NO; |
1266 | + @try { | ||
1267 | + @synchronized (_DatabaseLock) { | ||
1268 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1269 | + } | ||
1270 | + } | ||
1271 | + @catch (NSException *exception) { | ||
1272 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1273 | + if (failure) { | ||
1274 | + NSError *error = nil; | ||
1275 | + failure(error); | ||
1276 | + } | ||
1277 | + } | ||
1278 | + @finally { | ||
1279 | +// NSLog(@"Finally condition"); | ||
1280 | + } | ||
1281 | + | ||
1282 | + if (tableExist == YES) { | ||
1171 | NSString *refreshToken = @""; | 1283 | NSString *refreshToken = @""; |
1172 | NSString *clientId = @""; | 1284 | NSString *clientId = @""; |
1173 | NSString *clientSecret = @""; | 1285 | NSString *clientSecret = @""; |
... | @@ -1212,7 +1324,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1212,7 +1324,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1212 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; | 1324 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; |
1213 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; | 1325 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; |
1214 | [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { | 1326 | [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { |
1215 | - if (success && ([_db tableExists:@"requestVariables"] == YES)) { | 1327 | + |
1328 | + BOOL tableExist = NO; | ||
1329 | + @try { | ||
1330 | + @synchronized (_DatabaseLock) { | ||
1331 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1332 | + } | ||
1333 | + } | ||
1334 | + @catch (NSException *exception) { | ||
1335 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1336 | + if (failure) { | ||
1337 | + NSError *error = nil; | ||
1338 | + failure(error); | ||
1339 | + } | ||
1340 | + } | ||
1341 | + @finally { | ||
1342 | + // NSLog(@"Finally condition"); | ||
1343 | + } | ||
1344 | + | ||
1345 | + if (success && (tableExist == YES)) { | ||
1216 | // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; | 1346 | // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; |
1217 | // NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; | 1347 | // NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; |
1218 | // success(successResponse); | 1348 | // success(successResponse); |
... | @@ -1263,7 +1393,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1263,7 +1393,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1263 | 1393 | ||
1264 | - (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1394 | - (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
1265 | { | 1395 | { |
1266 | - if ([_db tableExists:@"requestVariables"] == YES) { | 1396 | + |
1397 | + BOOL tableExist = NO; | ||
1398 | + @try { | ||
1399 | + @synchronized (_DatabaseLock) { | ||
1400 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1401 | + } | ||
1402 | + } | ||
1403 | + @catch (NSException *exception) { | ||
1404 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1405 | + if (failure) { | ||
1406 | + NSError *error = nil; | ||
1407 | + failure(error); | ||
1408 | + } | ||
1409 | + } | ||
1410 | + @finally { | ||
1411 | +// NSLog(@"Finally condition"); | ||
1412 | + } | ||
1413 | + | ||
1414 | + if (tableExist == YES) { | ||
1267 | NSString *refreshToken = @""; | 1415 | NSString *refreshToken = @""; |
1268 | NSString *clientId = @""; | 1416 | NSString *clientId = @""; |
1269 | NSString *clientSecret = @""; | 1417 | NSString *clientSecret = @""; |
... | @@ -1307,7 +1455,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1307,7 +1455,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1307 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; | 1455 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; |
1308 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; | 1456 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; |
1309 | [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { | 1457 | [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { |
1310 | - if (success && ([_db tableExists:@"requestVariables"] == YES)) { | 1458 | + |
1459 | + BOOL tableExist = NO; | ||
1460 | + @try { | ||
1461 | + @synchronized (_DatabaseLock) { | ||
1462 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1463 | + } | ||
1464 | + } | ||
1465 | + @catch (NSException *exception) { | ||
1466 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1467 | + if (failure) { | ||
1468 | + NSError *error = nil; | ||
1469 | + failure(error); | ||
1470 | + } | ||
1471 | + } | ||
1472 | + @finally { | ||
1473 | + // NSLog(@"Finally condition"); | ||
1474 | + } | ||
1475 | + | ||
1476 | + if (success && (tableExist == YES)) { | ||
1311 | // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; | 1477 | // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; |
1312 | // NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; | 1478 | // NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; |
1313 | // success(successResponse); | 1479 | // success(successResponse); |
... | @@ -1358,7 +1524,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1358,7 +1524,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1358 | 1524 | ||
1359 | - (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1525 | - (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
1360 | { | 1526 | { |
1361 | - if ([_db tableExists:@"requestVariables"] == YES) { | 1527 | + |
1528 | + BOOL tableExist = NO; | ||
1529 | + @try { | ||
1530 | + @synchronized (_DatabaseLock) { | ||
1531 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1532 | + } | ||
1533 | + } | ||
1534 | + @catch (NSException *exception) { | ||
1535 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1536 | + if (failure) { | ||
1537 | + NSError *error = nil; | ||
1538 | + failure(error); | ||
1539 | + } | ||
1540 | + } | ||
1541 | + @finally { | ||
1542 | +// NSLog(@"Finally condition"); | ||
1543 | + } | ||
1544 | + | ||
1545 | + if (tableExist == YES) { | ||
1362 | NSString *refreshToken = @""; | 1546 | NSString *refreshToken = @""; |
1363 | NSString *clientId = @""; | 1547 | NSString *clientId = @""; |
1364 | NSString *clientSecret = @""; | 1548 | NSString *clientSecret = @""; |
... | @@ -1402,7 +1586,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1402,7 +1586,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1402 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; | 1586 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; |
1403 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; | 1587 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; |
1404 | [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { | 1588 | [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { |
1405 | - if (success && ([_db tableExists:@"requestVariables"] == YES)) { | 1589 | + |
1590 | + BOOL tableExist = NO; | ||
1591 | + @try { | ||
1592 | + @synchronized (_DatabaseLock) { | ||
1593 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1594 | + } | ||
1595 | + } | ||
1596 | + @catch (NSException *exception) { | ||
1597 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1598 | + if (failure) { | ||
1599 | + NSError *error = nil; | ||
1600 | + failure(error); | ||
1601 | + } | ||
1602 | + } | ||
1603 | + @finally { | ||
1604 | + // NSLog(@"Finally condition"); | ||
1605 | + } | ||
1606 | + | ||
1607 | + if (success && (tableExist == YES)) { | ||
1406 | // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; | 1608 | // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; |
1407 | // NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; | 1609 | // NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; |
1408 | // success(successResponse); | 1610 | // success(successResponse); |
... | @@ -1437,7 +1639,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1437,7 +1639,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1437 | // success(successResponse); | 1639 | // success(successResponse); |
1438 | // } failureBlock:^(NSError *error) { | 1640 | // } failureBlock:^(NSError *error) { |
1439 | if (failure) { | 1641 | if (failure) { |
1440 | - if ([_db tableExists:@"requestVariables"] == YES) { | 1642 | + |
1643 | + BOOL tableExist = NO; | ||
1644 | + @try { | ||
1645 | + @synchronized (_DatabaseLock) { | ||
1646 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
1647 | + } | ||
1648 | + } | ||
1649 | + @catch (NSException *exception) { | ||
1650 | + NSLog(@"tableExists error: %@", exception.reason); | ||
1651 | + } | ||
1652 | + @finally { | ||
1653 | + // NSLog(@"Finally condition"); | ||
1654 | + } | ||
1655 | + | ||
1656 | + if (tableExist == YES) { | ||
1441 | @synchronized (_DatabaseLock) { | 1657 | @synchronized (_DatabaseLock) { |
1442 | [_db executeUpdate:@"DROP TABLE requestVariables"]; | 1658 | [_db executeUpdate:@"DROP TABLE requestVariables"]; |
1443 | } | 1659 | } |
... | @@ -4775,11 +4991,23 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) | ... | @@ -4775,11 +4991,23 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) |
4775 | // [self initDBIfNeeded]; | 4991 | // [self initDBIfNeeded]; |
4776 | // [self restore]; | 4992 | // [self restore]; |
4777 | 4993 | ||
4994 | + BOOL tableExist = NO; | ||
4995 | + @try { | ||
4996 | + @synchronized (_DatabaseLock) { | ||
4997 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
4998 | + } | ||
4999 | + } | ||
5000 | + @catch (NSException *exception) { | ||
5001 | + NSLog(@"tableExists error: %@", exception.reason); | ||
5002 | + } | ||
5003 | + @finally { | ||
5004 | +// NSLog(@"Finally condition"); | ||
5005 | + } | ||
4778 | //Set HTTP Headers | 5006 | //Set HTTP Headers |
4779 | time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; | 5007 | time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; |
4780 | // NSString *accessToken = [NSString alloc]; | 5008 | // NSString *accessToken = [NSString alloc]; |
4781 | NSString *accessToken = @""; | 5009 | NSString *accessToken = @""; |
4782 | - if (([_db open] == YES) && ([_db tableExists:@"requestVariables"] == YES)) { | 5010 | + if (([_db open] == YES) && (tableExist == YES)) { |
4783 | // FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 5011 | // FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; |
4784 | // while ([accessTokenSet next]) { | 5012 | // while ([accessTokenSet next]) { |
4785 | // accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | 5013 | // accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; |
... | @@ -4937,11 +5165,23 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) | ... | @@ -4937,11 +5165,23 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) |
4937 | // [self initDBIfNeeded]; | 5165 | // [self initDBIfNeeded]; |
4938 | // [self restore]; | 5166 | // [self restore]; |
4939 | 5167 | ||
5168 | + BOOL tableExist = NO; | ||
5169 | + @try { | ||
5170 | + @synchronized (_DatabaseLock) { | ||
5171 | + tableExist = [_db tableExists:@"requestVariables"]; | ||
5172 | + } | ||
5173 | + } | ||
5174 | + @catch (NSException *exception) { | ||
5175 | + NSLog(@"tableExists error: %@", exception.reason); | ||
5176 | + } | ||
5177 | + @finally { | ||
5178 | +// NSLog(@"Finally condition"); | ||
5179 | + } | ||
4940 | //Set HTTP Headers | 5180 | //Set HTTP Headers |
4941 | time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; | 5181 | time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; |
4942 | // NSString *accessToken = [NSString alloc]; | 5182 | // NSString *accessToken = [NSString alloc]; |
4943 | NSString *accessToken = @""; | 5183 | NSString *accessToken = @""; |
4944 | - if (([_db open] == YES) && ([_db tableExists:@"requestVariables"] == YES)) { | 5184 | + if (([_db open] == YES) && (tableExist == YES)) { |
4945 | @try { | 5185 | @try { |
4946 | @synchronized (_DatabaseLock) { | 5186 | @synchronized (_DatabaseLock) { |
4947 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 5187 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | ... | ... |
-
Please register or login to post a comment