Manos Chorianopoulos

fix db select crash

......@@ -697,12 +697,26 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
[self createDBIfNeeded];
[self initDBIfNeeded];
[self restore];
NSString *accessToken = [NSString alloc];
// NSString *accessToken = [NSString alloc];
NSString *accessToken = @"";
if ([_db tableExists:@"requestVariables"] == YES) {
@try {
FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
while ([accessTokenSet next]) {
accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
}
}
@catch (NSException *exception) {
NSLog(@"SELECT accessToken error: %@", exception.reason);
}
@finally {
// NSLog(@"Finally condition");
}
// FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
// while ([accessTokenSet next]) {
// accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
// }
return accessToken;
}
return @"";
......@@ -1069,24 +1083,40 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
if ([_db tableExists:@"requestVariables"] == YES) {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
// NSString *refreshToken = [NSString alloc];
NSString *refreshToken = @"";
NSString *clientId = @"";
NSString *clientSecret = @"";
@try {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
// NSString *refreshToken = @"";
while ([refreshTokenSet next]) {
refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue];
}
FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"];
// NSString *clientId = [NSString alloc];
NSString *clientId = @"";
// NSString *clientId = [NSString alloc];
// NSString *clientId = @"";
while ([clientIdSet next]) {
clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue];
}
FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"];
// NSString *clientSecret = [NSString alloc];
NSString *clientSecret = @"";
// NSString *clientSecret = [NSString alloc];
// NSString *clientSecret = @"";
while ([clientSecretSet next]) {
clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue];
}
}
@catch (NSException *exception) {
NSLog(@"SELECT Token error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
......@@ -1125,24 +1155,39 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
if ([_db tableExists:@"requestVariables"] == YES) {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
// NSString *refreshToken = [NSString alloc];
NSString *refreshToken = @"";
NSString *clientId = @"";
NSString *clientSecret = @"";
@try {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
// NSString *refreshToken = @"";
while ([refreshTokenSet next]) {
refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue];
}
FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"];
// NSString *clientId = [NSString alloc];
NSString *clientId = @"";
// NSString *clientId = [NSString alloc];
// NSString *clientId = @"";
while ([clientIdSet next]) {
clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue];
}
FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"];
// NSString *clientSecret = [NSString alloc];
NSString *clientSecret = @"";
// NSString *clientSecret = [NSString alloc];
// NSString *clientSecret = @"";
while ([clientSecretSet next]) {
clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue];
}
}
@catch (NSException *exception) {
NSLog(@"SELECT Token error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
......@@ -1181,24 +1226,39 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
if ([_db tableExists:@"requestVariables"] == YES) {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
// NSString *refreshToken = [NSString alloc];
NSString *refreshToken = @"";
NSString *clientId = @"";
NSString *clientSecret = @"";
@try {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
// NSString *refreshToken = @"";
while ([refreshTokenSet next]) {
refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue];
}
FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"];
// NSString *clientId = [NSString alloc];
NSString *clientId = @"";
// NSString *clientId = [NSString alloc];
// NSString *clientId = @"";
while ([clientIdSet next]) {
clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue];
}
FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"];
// NSString *clientSecret = [NSString alloc];
NSString *clientSecret = @"";
// NSString *clientSecret = [NSString alloc];
// NSString *clientSecret = @"";
while ([clientSecretSet next]) {
clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue];
}
}
@catch (NSException *exception) {
NSLog(@"SELECT Token error: %@", exception.reason);
if (failure) {
NSError *error = nil;
failure(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
......@@ -4526,12 +4586,29 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
NSString *accessToken = [NSString alloc];
// NSString *accessToken = [NSString alloc];
NSString *accessToken = @"";
if ([_db tableExists:@"requestVariables"] == YES) {
// FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
// while ([accessTokenSet next]) {
// accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
// }
@try {
FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
while ([accessTokenSet next]) {
accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
}
}
@catch (NSException *exception) {
NSLog(@"SELECT accessToken error: %@", exception.reason);
if (failureBlock) {
NSError *error = nil;
failureBlock(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
[_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"];
}
[_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"];
......@@ -4665,12 +4742,29 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
NSString *accessToken = [NSString alloc];
// NSString *accessToken = [NSString alloc];
NSString *accessToken = @"";
if ([_db tableExists:@"requestVariables"] == YES) {
@try {
FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
while ([accessTokenSet next]) {
accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
}
}
@catch (NSException *exception) {
NSLog(@"SELECT accessToken error: %@", exception.reason);
if (failureBlock) {
NSError *error = nil;
failureBlock(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
// FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"];
// while ([accessTokenSet next]) {
// accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue];
// }
[_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"];
}
[_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"];
......