I am trying to read from a csv file and add each row to a database in c++. The csv file is in the form id,firstname,surname,job my code is:

while (file.good()){getline (file, id, ',');getline (file, firstname, ',');getline (file, surname, ',');getline (file, job, ' ');cur->set_sql( "INSERT INTO staff VALUES (?, ?, ?, ?);" );cur->prepare();cur->bind(1, id);cur->bind(2, firstname);cur->bind(3, surname);cur->bind(4, job);cur->step();cur->reset();}

but when I run the code it returns the error Sqlite error: Could not reset the virtual machine. I do not understand what this means or how to solve it. I searched the error on google but I can't find anything about it

share|improve this question
  • Have you looked at the return code of step?– UKMonkeyFeb 13 at 17:15
  • @UKMonkey it returns 0– Rory DanesFeb 13 at 17:20
  • Call sqlite3_errmsg() to get the actual error message.– CL.Feb 13 at 19:18
  • @CL. It returns 1 which means sqlite_error– Rory DanesFeb 13 at 22:18
  • sqlite3_errmsg() does not return a number.– CL.Feb 14 at 7:37

Error comes from libsqlite.hpp (check search on github.com)

void reset(){int rc=sqlite3_reset(this->_s);if (rc !=SQLITE_OK) {exception e("Could not reset the virtual machine.");throw e;}this->_valid=true;this->_has_row=false;this->_prepared=false;}

I haven't digg into this but it looks like sqilte query contain error or can't run.

share|improve this answer

    Your Answer

     
    discard

    By posting your answer, you agree to the privacy policy and terms of service.

    Not the answer you're looking for? Browse other questions tagged or ask your own question.