Hi in my application i have stored data in my local database sqlite3. Now i have to upload the data form local database sqlite3 to online server. For retrieving the data i have used the dataDictionary to get all the data form the sqlite3 database.
In my h file i have my url to insert the data in to my online server like this.
#define kPostURL @"url"
#define Kname @"name"
#define kphone @"phone"
#define karea @"area"
#define kcity @"city"
In this below code i have stored the all the data in data dictionary and i have stored the data into a nsmutable array called array. If i print the array in log its showing all the data. The problem is now how to pass this nsmutable data into online server using the post method.
NSMutableArray *array = [[NSMutableArray alloc] init];
entries = [[NSMutableArray alloc] init];
[self openDB];
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM reg"];
const char *query_stmt = [sql UTF8String];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, nil)==SQLITE_OK) {
while (sqlite3_step(statement)==SQLITE_ROW) {
NSMutableDictionary *_dataDictionary=[[NSMutableDictionary alloc] init];
NSString *date = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
field1Str= date;
NSString *customer = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
field2Str = customer;
NSString *code1 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)];
field3Str = code1;
NSString *code2 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,3)];
field4Str = code2;
//NSString *str = [[NSString alloc]initWithFormat:@"%@ - %@ - %@ - %@",field1Str,field2Str,field3Str,field4Str];
//[entries addObject:str];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",field1Str] forKey:@"Kname"];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",field2Str] forKey:@"kphone"];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",field3Str] forKey:@"karea"];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",field4Str] forKey:@"kcity"];
[array addObject:_dataDictionary];
In this below code I'm passing the data using post method to the online server that the data has already declare in the .m file but i don't how to nsmutablearray in the post method.
-(void) withName:(NSString *) na phone:(NSString *) ph are:(NSString *) arr cit:(NSString *) citt {
if (na!= nil && ph != nil && arr != nil && citt != nil ) {
NSMutableString *postString = [NSMutableString stringWithString:kPostURL];
[postString appendString:[NSString stringWithFormat:@"?%@=%@", Kname,na]];
[postString appendString:[NSString stringWithFormat:@"&%@=%@", kphone,ph]];
[postString appendString:[NSString stringWithFormat:@"&%@=%@", karea,arr]];
[postString appendString:[NSString stringWithFormat:@"&%@=%@", kcity,citt]];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request =[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:@"POST"];
postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
}
In this above code I'm passing the data by a button click . Please tell how to make it have been stuck here for long time its eating my head. Please give me some solution.
- (IBAction)send:(id)sender {
[self withName:field1Str phone:field2Str are:field3Str cit:field4Str];
}
Thanks.