Reputation: 556
My code is:
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);
I guess I am doing something wrong, cant figure it out. Its showing some error occurred msg, whenever i add data to sqlite. And also getting exception NSInternalInconsistencyException no such table:AnimalTable. But AnimalTable exist and when i execute the query in sqlmanager it runs properly.
Upvotes: 1
Views: 96
Reputation: 16864
Following code is use for the storing the blob type of data store,
May this helping to you
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);
}
Upvotes: 1