I need to convert const char type data to NSString object type because sqlite database return char * type data. For that I have used NSString Class method stringWithUTF8strin but it is returning NULL.It fetches sqlite text type data.
Here is my code:
-(void)getAllData:(const char *)sqlQuery
{
name=[[NSMutableArray alloc]init];
department=[[NSMutableArray alloc]init];
image=[[NSMutableArray alloc]init];
testimonial=[[NSMutableArray alloc]init];
@try
{
NSArray *pathArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *final_phone_path=[[pathArray objectAtIndex:0]stringByAppendingPathComponent:@"amarinf5_excel.sqlite"];
NSLog(@"%@",final_phone_path);
NSFileManager *myFileManager=[NSFileManager defaultManager];
if(![myFileManager fileExistsAtPath:final_phone_path])
{
NSLog(@"file doesnot exist");
}
if( sqlite3_open([final_phone_path UTF8String], &dataBAse)!=SQLITE_OK)
{
NSLog(@"could not be able to open the file");
}
const char *sql=sqlQuery;
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(dataBAse, sql, -1, &statement, nil)!=SQLITE_OK)
{
NSLog(@"Error message fail to prepare statement %s",sqlite3_errmsg(dataBAse));
}
while(sqlite3_step(statement)==SQLITE_ROW)
{
const char *name1=(char *)sqlite3_column_text(statement, 0);
const char *deprtment1=(char *)sqlite3_column_text(statement, 1);
const char *image1= (char *)sqlite3_column_text(statement, 2);
**const char *testimonial1=(char *)sqlite3_column_text(statement, 3);
NSLog(@"%@",[NSString stringWithUTF8String:testimonial1]);**
NSLog(@"%s",testimonial1);
NSLog(@"%@",[NSString stringWithUTF8String:image1]);
[name addObject:[NSString stringWithUTF8String:name1]];
[department addObject:[NSString stringWithUTF8String:deprtment1]];
[image addObject:[NSString stringWithUTF8String:image1]];
//[testimonial addObject:[NSString stringWithUTF8String:testimonial1]];
NSLog(@"%@",[NSString stringWithUTF8String:testimonial1]);
}
if (sqlite3_finalize(statement) != SQLITE_OK)
{
NSLog(@"Failed to finalize data statement, normally error handling here.");
}
if (sqlite3_close(dataBAse) != SQLITE_OK)
{
NSLog(@"Failed to close database, normally error handling here.");
}
}
@catch (NSException *exception) {
NSLog(@"An exception occurred: %@", [exception reason]);
}
@finally {
}
}
Maulik M. Kamani
ASP.net Developer
Tech Sture Technology Pvt. Ltd the data i get in testimonial1 but could not be able to covert is there any possibility that it contains html tags – pratik371987 Jun 06 '14 at 09:07