mardi 29 mars 2016

sqlite Database not Entering prepare statment?

Please check my code, I am create Sqlite Database. why sqlite_prepar_v2 Statement not working? I created Database through Firefox. my Database Name is zaakitDB. In my database two tables is there, Mensfashion and womensfashion. please check my code find the issue.I tried to find issue. Help me friends

-(void) openDataBaseForHealthTips
{    
    NSString * completePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0]stringByAppendingPathComponent:@"zaakitDB.sqlite"];
    NSLog(@"Complete Path :%@",completePath);
    NSFileManager * manager = [NSFileManager defaultManager];
    if([manager fileExistsAtPath:completePath])
    {

        const char * changeCompletePath = [completePath UTF8String];
        sqlite3_open(changeCompletePath, &dataBaseHandler);
    }
    else
    {

        NSString * bundlePath = [[NSBundle mainBundle]pathForResource:@"zaakitDB" ofType:@"sqlite"];

        NSError * error;
        [manager copyItemAtPath:bundlePath toPath:completePath error:&error];

        const char * changeCompletePath = [completePath UTF8String];
        sqlite3_open(changeCompletePath, &dataBaseHandler);
    }
   }

//method for close data base
-(void)closeDataBaseForHealthTips
{
    sqlite3_close(dataBaseHandler);     
}  
-(void)backGroundWork
{
    [self openDataBaseForHealthTips];
    [self performSelectorInBackground:@selector(selectDataForHealthTips) withObject:nil];

}

-(void)selectDataForHealthTips
{  
     imagesArray= [NSMutableArray array];
     pricearray = [NSMutableArray array];
     itemnamearray = [NSMutableArray array];

    NSString * selectQuery = [NSString stringWithFormat:@"SELECT * FROM MENSFASHION"];
    const char * convertSelectQuery = [selectQuery UTF8String];
    sqlite3_stmt * prepareSelectStatement;

    NSLog(@"items %d",sqlite3_prepare_v2(dataBaseHandler, convertSelectQuery, -1, &prepareSelectStatement, NULL));

    sqlite3_prepare_v2(dataBaseHandler, convertSelectQuery, -1,&prepareSelectStatement, NULL);

    while (sqlite3_step(prepareSelectStatement) == SQLITE_ROW)
    {  
                //code for image storage
        const void *rawPhoto=sqlite3_column_blob(prepareSelectStatement, 0);

        int photoLength =sqlite3_column_bytes(prepareSelectStatement, 0);
        // self.photoData = [[NSData alloc] initWithBytes:rawPhoto length:photoLength];
        self.photoData = [NSData dataWithBytes:rawPhoto length:photoLength];

        //code for data

        NSString * price = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(prepareSelectStatement,1)];

        NSString * itemname = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(prepareSelectStatement,2)];

        [imagesArray addObject:self.photoData];
        [pricearray addObject:price];
        [itemnamearray addObject:itemname];
    }

    [self closeDataBaseForHealthTips];
    [custom.itemTableview reloadData];
    [custom.itemTableview setScrollEnabled:YES];
}

Aucun commentaire:

Enregistrer un commentaire