Hi All
this is code which am using for the fetching data fro DB through my API
Some time application crashes in the directMySQL function after the log directmysql.. at end of directMySQLQuery ok
is any thing wrong in code
Please suggest me what should I do
Thanks
Monaj
this is code which am using for the fetching data fro DB through my API
Some time application crashes in the directMySQL function after the log directmysql.. at end of directMySQLQuery ok
Code:
-(NSData*)executeQuery:(NSString*)query WithAction:(NSString*)doAction{
NSLog(@"within ExecuteQuery:WithAction: Query is: %@ and Action is: %@",query,doAction);
NSString *returnResult;
@try {
NSString *returnResult;
NSMutableURLRequest *postRequest;
NSError *error;
NSData *searchData;
NSHTTPURLResponse *response;
postRequest=[self directMySQLQuery:query WithAction:doAction];
NSLog(@"after directMYSQL in QueryByPost- performQuery... ErrorLogMsg");
searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
returnResult = [[NSString alloc] initWithData:searchData encoding:NSASCIIStringEncoding];
NSString *resultToBeCompared=[returnResult stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"result obtained - %@/ resultToBeCompared - %@",returnResult,resultToBeCompared);
if(![resultToBeCompared isEqualToString:@""]){
}else {
sleep(10);
postRequest=[self directMySQLQuery:query WithAction:doAction];
searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
if(![resultToBeCompared isEqualToString:@""]){
}else {
sleep(10);
postRequest=[self directMySQLQuery:query WithAction:doAction];
searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
if(![resultToBeCompared isEqualToString:@""]){
}else {
sleep(10);
postRequest=[self directMySQLQuery:query WithAction:doAction];
searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
if(![resultToBeCompared isEqualToString:@""]){
}else {
sleep(10);
postRequest=[self directMySQLQuery:query WithAction:doAction];
searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
if(![resultToBeCompared isEqualToString:@""]){
}else {
return nil;
}
}
}
}
}
returnResult = [[NSString alloc] initWithData:searchData encoding:NSASCIIStringEncoding];
NSLog(@"final result returned- %@",returnResult);
return searchData;
}
@catch (NSException * e) {
NSLog(@"within QueryByPost , execurteQuery:WithAction - %@",[e description]);
return nil;
}
}
-(NSMutableURLRequest *)directMySQLQuery:(NSString*)query WithAction:(NSString*)doAction{
@try{
NSLog(@"within directMySQLQuery:WithAction");
NSLog(@"Query is: %@ and Action is: %@",query,doAction);
NSString *stringBoundary,*contentType;
NSURL *cgiUrl ;
NSMutableURLRequest *postRequest;
NSMutableData *postBody;
NSString *ans=@"434";
cgiUrl = [NSURL URLWithString:@"https://keysoftwareservices.com/API.php"];
postRequest = [NSMutableURLRequest requestWithURL:cgiUrl];
[postRequest setHTTPMethod:@"POST"];
stringBoundary = [NSString stringWithString:@"0000RCSQueryxxxxxx"];
contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", stringBoundary];
[postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
//setting up the body:
postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"\r\n\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"code\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:ans] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"action\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:doAction] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"devmode\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"devmode"]] dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"devmode...%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"devmode"]);
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"q\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:query] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postRequest setHTTPBody:postBody];
NSLog(@"directmysql.. at end of directMySQLQuery ok");
// Application crashes after the upper log
return [postRequest mutableCopy];
}@catch (NSException * e) {
NSLog(@"NSException %@",e);
NSRunAlertPanel(@"Error Panel", @"Within QueryByPost- directMySQLQuery...%@", @"OK", nil, nil,e);
return nil;
}
}
is any thing wrong in code
Please suggest me what should I do
Thanks
Monaj