I'm trying to insert a binary file to sqlite database. I'm getting "bind or column index out of range" error. I've no idea why I'm getting that error, everything seems to be in order. I've marked the location of error with a comment. I've double checked that the file exists and it's size is correct.
private void InsertBlob(uint PID, uint MID, int CR, int CG, int CB){
ifstream file("my_file.bin", ios::in | ios::binary);
file.seekg(0, ifstream::end);
streampos size = file.tellg();
file.seekg(0);
//read file to buffer
char* buffer = new char[size];
file.read(buffer, size);
//C++ string build, MBinary is blob others are Integers
string Command = "BEGIN; INSERT INTO Dat (PID,MID,CID_R,CID_G,CID_B,MBinary) VALUES (" + to_string(PID) + "," + to_string(MID) + "," + to_string(CR) + "," + to_string(CG) + "," + to_string(CB) + ",?);COMMIT;";
//convert string to char
char c_style_string[1024];
strncpy(c_style_string, Command.c_str(), sizeof(c_style_string));
c_style_string[sizeof(c_style_string) - 1] = 0;
int rc;
sqlite3_open("AnalysisDatabase.db3", &db);
sqlite3_stmt *stmt = NULL;
rc = sqlite3_prepare_v2(db,c_style_string,-1, &stmt, NULL);
**//following line throws the error: bind or column index out of range**
rc = sqlite3_bind_blob(stmt, 1, buffer, size, SQLITE_STATIC);
rc = sqlite3_step(stmt);
sqlite3_finalize(stmt);
sqlite3_close(db);
}
Aucun commentaire:
Enregistrer un commentaire