1

我的代码是:

const char *sqlInsertString;
sqlite3_stmt *addStatement;
sqlInsertString=sqlite3_mprintf("insert into AnimalTable(name,propertyID,animalID,breed,dateofbirth,sex,notes,imageData) values" "('%s','%s','%s','%s','%s','%s','%s','%d')",nameString,propertyString,animalidString,breedString,dateofbirth,sexString,notesString,imageData);
    if (sqlite3_open([sqlFile UTF8String],&database)==SQLITE_OK) {
        sqlite3_prepare_v2(database, sqlInsertString, -1, &addStatement, NULL);
        if (sqlite3_step(addStatement)==SQLITE_DONE) {
            sqlite3_bind_blob(addStatement, 1, [imageData bytes], [imageData length], NULL);
            sqlite3_finalize(addStatement);
            NSLog(@"Data saved");

        }
        else
            NSLog(@"Some Error occurred");
    }

    sqlite3_close(database);

我想我做错了什么,无法弄清楚。每当我将数据添加到 sqlite 时,它​​都会显示一些错误消息。并且还得到异常 NSInternalInconsistencyException no such table:AnimalTable。但是 AnimalTable 存在,当我在 sqlmanager 中执行查询时它运行正常。

4

1 回答 1

1

以下代码用于存储 blob 类型的数据存储,

愿这对你有帮助

 if(sqlite3_prepare_v2(database, sqlInsertQry, -1, &compiledStmt, NULL) == SQLITE_OK ){
                for (NSDictionary *dObj in arForData) {
                     sqlite3_bind_blob(compiledStmt,1,[[dObj valueForKey:@"NotiData"] bytes],[[dObj valueForKey:@"NotiData"] length],NULL);
                    PUT_Date(2,@"fireDate");


                    NSUInteger err = sqlite3_step(compiledStmt);
                    if (err != SQLITE_DONE){
                        //NSLog(@"error while binding %d %s",err, sqlite3_errmsg(database));
                        //NSLog(@"%@",dObj);
                    }
                    sqlite3_reset(compiledStmt);
                }
                sqlite3_finalize(compiledStmt);     
            } 
于 2012-04-11T12:15:26.247 回答