sqlite数据库没有输入准备状态?

时间:2016-03-29 09:52:07

标签: sqlite ios7

请检查我的代码,我正在创建一个SQLite数据库。为什么sqlite_prepar_v2声明不起作用?我通过Firefox创建了数据库。我的数据库名称是zaakitDB。在我的数据库中有两个表,Mensfashion和womensfashion。

-(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];
}

0 个答案:

没有答案