1

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.

1
  • offtopic: please use for future projects FMDatabase: github.com/ccgus/fmdb Commented Apr 11, 2012 at 11:55

1 Answer 1

1

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);     
            } 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.