Manos Chorianopoulos

fix db error

...@@ -1168,11 +1168,27 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -1168,11 +1168,27 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
1168 NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; 1168 NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
1169 NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; 1169 NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
1170 [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { 1170 [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) {
1171 - if (success) { 1171 + if (success && ([_db tableExists:@"requestVariables"] == YES)) {
1172 +// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
1173 +// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
1174 +// success(successResponse);
1175 +
1176 + @try {
1172 [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; 1177 [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
1173 NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; 1178 NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
1174 success(successResponse); 1179 success(successResponse);
1175 } 1180 }
1181 + @catch (NSException *exception) {
1182 + NSLog(@"UPDATE Token error: %@", exception.reason);
1183 + if (failure) {
1184 + NSError *error = nil;
1185 + failure(error);
1186 + }
1187 + }
1188 + @finally {
1189 + // NSLog(@"Finally condition");
1190 + }
1191 + }
1176 } failureBlock:^(NSError *error) { 1192 } failureBlock:^(NSError *error) {
1177 if (failure) { 1193 if (failure) {
1178 NSDictionary* dict = [NSDictionary alloc]; 1194 NSDictionary* dict = [NSDictionary alloc];
...@@ -1239,11 +1255,27 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -1239,11 +1255,27 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
1239 NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; 1255 NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
1240 NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; 1256 NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
1241 [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { 1257 [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) {
1242 - if (success) { 1258 + if (success && ([_db tableExists:@"requestVariables"] == YES)) {
1259 +// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
1260 +// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
1261 +// success(successResponse);
1262 +
1263 + @try {
1243 [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; 1264 [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
1244 NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; 1265 NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
1245 success(successResponse); 1266 success(successResponse);
1246 } 1267 }
1268 + @catch (NSException *exception) {
1269 + NSLog(@"UPDATE Token error: %@", exception.reason);
1270 + if (failure) {
1271 + NSError *error = nil;
1272 + failure(error);
1273 + }
1274 + }
1275 + @finally {
1276 + // NSLog(@"Finally condition");
1277 + }
1278 + }
1247 } failureBlock:^(NSError *error) { 1279 } failureBlock:^(NSError *error) {
1248 if (failure) { 1280 if (failure) {
1249 NSDictionary* dict = [NSDictionary alloc]; 1281 NSDictionary* dict = [NSDictionary alloc];
...@@ -1310,11 +1342,27 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -1310,11 +1342,27 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
1310 NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; 1342 NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
1311 NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; 1343 NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
1312 [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { 1344 [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) {
1313 - if (success) { 1345 + if (success && ([_db tableExists:@"requestVariables"] == YES)) {
1346 +// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
1347 +// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
1348 +// success(successResponse);
1349 +
1350 + @try {
1314 [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]]; 1351 [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
1315 NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; 1352 NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
1316 success(successResponse); 1353 success(successResponse);
1317 } 1354 }
1355 + @catch (NSException *exception) {
1356 + NSLog(@"UPDATE Token error: %@", exception.reason);
1357 + if (failure) {
1358 + NSError *error = nil;
1359 + failure(error);
1360 + }
1361 + }
1362 + @finally {
1363 + // NSLog(@"Finally condition");
1364 + }
1365 + }
1318 } failureBlock:^(NSError *error) { 1366 } failureBlock:^(NSError *error) {
1319 if (failure) { 1367 if (failure) {
1320 NSDictionary* dict = [NSDictionary alloc]; 1368 NSDictionary* dict = [NSDictionary alloc];
......