Hello! I'm coding a simple method in C++ to insert a tuple in a small
database. The database has a table called 'user', with 3 fields (id -
the primary key, name, and a image).
I mapped these fields in a class - id is an int, name is a std::string
and image is a std::vector of unsigned char. In this point, I'm ok. To
insert this in the database, I write the following method:
bool DatabaseClass::insertAdminUser(User user) {
int rc;
sqlite3_stmt *statement;
// mydb is defined in the private area of the class
rc = sqlite3_open_v2("database.db", &mydb, SQLITE_OPEN_READWRITE, NULL);
if (rc != SQLITE_OK) {
sqlite3_close(mydb);
return false;
}
rc = sqlite3_prepare_v2(mydb, "INSERT INTO users (name, isadmin,
photo) VALUES (?, 1, ?)", -1, &statement, NULL);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);
return false;
}
int i = 0;
rc = sqlite3_bind_text(statement, ++i, user.getName().c_str(), -1,
SQLITE_TRANSIENT);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);
return false;
}
rc = sqlite3_bind_blob(statement, ++i, (void*) user.getPhoto()[0],
user.getPhoto().size(), SQLITE_STATIC);
if (rc != SQLITE_OK) {
sqlite3_finalize(statement);
sqlite3_close(banco);
return false;
}
rc = sqlite3_step(statement); // The app crashes here!
if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
sqlite3_finalize(statement);
sqlite3_close(mydb);
return false;
}
sqlite3_finalize(statement);
sqlite3_close(banco);
return true;
}
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users