Hello i have a problem in storing data on server from sqlite database. Here is my code
NSString *query = @"SELECT ROW,PHOTO1 BLOB,BLG_NAME TEXT,ST_NO TEXT,ST_NAME TEXT,ST_DIR TEXT,MUNI TEXT,PROVINCE TEXT,BLG_TYPE TEXT,BLG_ACC TEXT,BLG_AMN TEXT,LONGI TEXT,LATI TEXT FROM ATTRI4 WHERE FLAG = ?";
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK)
{
sqlite3_bind_int(statement,1,0);
while(sqlite3_step(statement)==SQLITE_ROW)
{
NSLog(@"Data==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 0)]);
NSLog(@"Data1==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 1)]);
NSLog(@"Data==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 2)]);
NSLog(@"Data1==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 3)]);
NSLog(@"Data==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 4)]);
NSLog(@"Data1==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 5)]);
NSLog(@"Data==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 6)]);
NSLog(@"Data1==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 7)]);
NSLog(@"Data==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 8)]);
NSLog(@"Data1==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 9)]);
NSLog(@"Data==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 10)]);
NSLog(@"Data1==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 11)]);
NSLog(@"Data==>%@",[NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 12)]);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"in retrival!!!!"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
NSString *data0 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 2)];
NSString *data1 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 3)];
NSString *data2 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 4)];
NSString *data3= [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 5)];
NSString *data4 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 6)];
NSString *data5 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 7)];
NSString *data6 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 8)];
NSString *data7 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 9)];
NSString *data8 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 10)];
NSString *data9 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 11)];
NSString *data10 = [NSString stringWithFormat: @"%s",(char *)sqlite3_column_text(statement, 12)];
NSString *data11 = @"123456788";
NSString *data12 = @"png";
NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement, 1) length:sqlite3_column_bytes(statement,1)];
if(data == nil)
NSLog(@"No image");
else
{
base64EncodedimageData = [self base64StringFromData:data length:[data length]];
NSLog(@"imagedataencded=%@",base64EncodedimageData);
// [imgarray1 addObject: base64EncodedimageData];
}
/********************** SYNC WITH THE SERVER ****************************/
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
"<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns7475=\"some URL/\">\n"
"<SOAP-ENV:Body>\n"
"<ns7475:saveFile xmlns:ns7475=\"http://demo.digi-corp.com:82/Nilesh/FDCT/img_server.php\">\n"
"<buildingName xsi:type=\"xsd:string\">%@</buildingName>\n"
"<streetNumber xsi:type=\"xsd:string\">%@</streetNumber>\n"
"<streetName xsi:type=\"xsd:string\">%@</streetName>\n"
"<streetDirection xsi:type=\"xsd:string\">%@</streetDirection>\n"
"<municipality xsi:type=\"xsd:string\">%@</municipality>\n"
"<province xsi:type=\"xsd:string\">%@</province>\n"
"<buildingType xsi:type=\"xsd:string\">%@</buildingType>\n"
"<buildingAccess xsi:type=\"xsd:string\">%@</buildingAccess>\n"
"<buildingAmenities xsi:type=\"xsd:string\">%@</buildingAmenities>\n"
"<longitude xsi:type=\"xsd:string\">%@</longitude>\n"
"<latitude xsi:type=\"xsd:string\">%@</latitude>\n"
"<devID xsi:type=\"xsd:string\">%@</devID>\n"
"<filetype xsi:type=\"xsd:string\">%@</filetype>\n"
"<filedata xsi:type=\"xsd:base64Binary\">%@</filedata>\n"
"</ns7475:saveFile>\n"
"</SOAP-ENV:Body>\n"
"</SOAP-ENV:Envelope>\n",data0,
data1,
data2,
data3,
data4,
data5,
data6,
data7,
data8,
data9,
data10,
data11,
data12,
base64EncodedimageData];
data0 = nil;
data1 = nil;
data2= nil;
data3= nil;
data4= nil;
data5= nil;
data6= nil;
data7= nil;
data8= nil;
data9= nil;
data10= nil;
data11= nil;
data12= nil;
base64EncodedimageData= nil;
recordctr++;
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:@"someURL"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=ISO-8859-1" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"some URL" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
NSLog( @"connection established");
//NSLog( webData);
}
else
{
NSLog(@"theConnection is NULL");
}
NSHTTPURLResponse *response = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest: theRequest
returningResponse:&response
error : &error];
NSLog(@"Response code= %d", [response statusCode] );
NSLog(@"Content-type : @", [[response allHeaderFields] objectForKey: @"Content-type"]);
if([response statusCode] >=200 && [response statusCode ] <300)
NSLog( @"connection established 1");
}
sqlite3_finalize(statement);
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
NSLog(@"webdatappende %@",webData);
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
NSLog(@"webdata=%@",webData);
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(theXML);
[theXML release];
if( xmlParser )
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
[connection release];
[webData release];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
if( [elementName isEqualToString:@"SOAP-ENV:Envelope"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
recordResults = TRUE;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if( recordResults )
{
[soapResults appendString: string];
NSLog( @" %@* ",string);
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:@"SOAP-ENV:Envelope"])
{
recordResults = FALSE;
NSLog( @"soap results= %@" ,soapResults);
NSLog( @"ele name=%@ ",elementName);
soapResults = nil;
}
}
now what's wrong here.I got response from server also but then again control go to [XML parse] and here it get exception
DONE. Received Bytes: 484
2009-05-13 12:33:34.215 Camera[1854:20b] <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:saveFileResponse xmlns:ns1="http://demo.digi-corp.com:82/Nilesh/FDCT/img_server.php"><return xsi:type="xsd:string">32</return></ns1:saveFileResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Program received signal: “EXC_BAD_ACCESS”.
Unable to disassemble objc_msgSend.
so plz help me on it..