Manos Chorianopoulos

handle db tableExists queries

......@@ -703,9 +703,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
[self createDBIfNeeded];
[self initDBIfNeeded];
[self restore];
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
// NSString *accessToken = [NSString alloc];
NSString *accessToken = @"";
if ([_db tableExists:@"requestVariables"] == YES) {
if (tableExist == YES) {
@try {
@synchronized (_DatabaseLock) {
FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
......@@ -732,9 +745,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
};
- (NSString*)getRefreshToken {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
// NSString *refreshToken = [NSString alloc];
NSString *refreshToken = @"";
if ([_db tableExists:@"requestVariables"] == YES) {
if (tableExist == YES) {
@try {
@synchronized (_DatabaseLock) {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
......@@ -761,9 +787,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}
- (NSString*)getClientId {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
// NSString *clientId = [NSString alloc];
NSString *clientId = @"";
if ([_db tableExists:@"requestVariables"] == YES) {
if (tableExist == YES) {
@try {
@synchronized (_DatabaseLock) {
FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"];
......@@ -790,9 +829,23 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}
- (NSString*)getClientSecret {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
// NSString *clientSecret = [NSString alloc];
NSString *clientSecret = @"";
if ([_db tableExists:@"requestVariables"] == YES) {
if (tableExist == YES) {
@try {
@synchronized (_DatabaseLock) {
FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"];
......@@ -964,7 +1017,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
@synchronized (_DatabaseLock) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
}
if ([_db tableExists:@"requestVariables"] == NO) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
if (tableExist == NO) {
@synchronized (_DatabaseLock) {
[_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))"];
WL_FMDBLogError
......@@ -1055,7 +1122,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
@synchronized (_DatabaseLock) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
}
if ([_db tableExists:@"requestVariables"] == NO) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
if (tableExist == NO) {
@synchronized (_DatabaseLock) {
[_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))"];
WL_FMDBLogError
......@@ -1158,7 +1239,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)updateRefreshTokenW:(NSString*)access_token :(NSString*)refresh_token
{
if ([_db tableExists:@"requestVariables"] == YES) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
if (tableExist == YES) {
@synchronized (_DatabaseLock) {
[_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", access_token, refresh_token];
}
......@@ -1167,7 +1262,24 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
if ([_db tableExists:@"requestVariables"] == YES) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
if (tableExist == YES) {
NSString *refreshToken = @"";
NSString *clientId = @"";
NSString *clientSecret = @"";
......@@ -1212,7 +1324,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
[self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) {
if (success && ([_db tableExists:@"requestVariables"] == YES)) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
if (success && (tableExist == YES)) {
// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
// success(successResponse);
......@@ -1263,7 +1393,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
if ([_db tableExists:@"requestVariables"] == YES) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
if (tableExist == YES) {
NSString *refreshToken = @"";
NSString *clientId = @"";
NSString *clientSecret = @"";
......@@ -1307,7 +1455,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
[self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) {
if (success && ([_db tableExists:@"requestVariables"] == YES)) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
if (success && (tableExist == YES)) {
// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
// success(successResponse);
......@@ -1358,7 +1524,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
if ([_db tableExists:@"requestVariables"] == YES) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
if (tableExist == YES) {
NSString *refreshToken = @"";
NSString *clientId = @"";
NSString *clientSecret = @"";
......@@ -1402,7 +1586,25 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
[self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) {
if (success && ([_db tableExists:@"requestVariables"] == YES)) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
if (success && (tableExist == YES)) {
// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
// success(successResponse);
......@@ -1437,7 +1639,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
// success(successResponse);
// } failureBlock:^(NSError *error) {
if (failure) {
if ([_db tableExists:@"requestVariables"] == YES) {
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
if (tableExist == YES) {
@synchronized (_DatabaseLock) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
}
......@@ -4775,11 +4991,23 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
// [self initDBIfNeeded];
// [self restore];
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
// NSString *accessToken = [NSString alloc];
NSString *accessToken = @"";
if (([_db open] == YES) && ([_db tableExists:@"requestVariables"] == YES)) {
if (([_db open] == YES) && (tableExist == YES)) {
// FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
// while ([accessTokenSet next]) {
// accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
......@@ -4937,11 +5165,23 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
// [self initDBIfNeeded];
// [self restore];
BOOL tableExist = NO;
@try {
@synchronized (_DatabaseLock) {
tableExist = [_db tableExists:@"requestVariables"];
}
}
@catch (NSException *exception) {
NSLog(@"tableExists error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
// NSString *accessToken = [NSString alloc];
NSString *accessToken = @"";
if (([_db open] == YES) && ([_db tableExists:@"requestVariables"] == YES)) {
if (([_db open] == YES) && (tableExist == YES)) {
@try {
@synchronized (_DatabaseLock) {
FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
......