我试图编写一个使用sqlite的示例项目。每次输入ID时,都会收到以下错误消息: 抛出'std :: __ cxx11 :: basic_string,std :: allocator>'
实例后终止调用有人可以帮助我吗?
Header Database.h
...
private:
void showMenu();
void addRecord();
void showRecord();
void openDB();
int nSelection;
sqlite3* db;
int rc;
std::string sql;
const unsigned char* uc_result_firstName;
const unsigned char* uc_result_lastName;
int nRowID;
std::string strFirstName;
std::string strLastName;
int nAge;
}; ...
cpp文件数据库.cpp
...
void Database::showRecord(){
std::cout << "Select ID -> ";
int nID;
std::string strBuffer = "";
std::cin >> strBuffer;
nID = std::stoi(strBuffer.c_str());
sqlite3_stmt* stmt;
rc = sqlite3_prepare_v2(db, "SELECT FirstName, LastName, Age"
" FROM customerTable"
" WHERE id = ?", -1, &stmt, NULL);
if (rc != SQLITE_OK)
throw std::string(sqlite3_errmsg(db));
rc = sqlite3_bind_int(stmt, 1, nID); // Using parameters ("?") is not
if (rc != SQLITE_OK) { // really necessary, but recommended
std::string errmsg(sqlite3_errmsg(db)); // (especially for strings) to avoid
sqlite3_finalize(stmt); // formatting problems and SQL
throw errmsg; // injection attacks.
}
rc = sqlite3_step(stmt);
if (rc != SQLITE_ROW && rc != SQLITE_DONE) {
std::string errmsg(sqlite3_errmsg(db));
sqlite3_finalize(stmt);
throw errmsg;
}
if (rc == SQLITE_DONE) {
sqlite3_finalize(stmt);
throw std::string("customer not found");
}
uc_result_firstName = sqlite3_column_text(stmt, 0);
uc_result_lastName = sqlite3_column_text(stmt, 1);
this->nRowID = nID;
this->strFirstName = std::string(reinterpret_cast<char const*>(uc_result_firstName));
this->strLastName = std::string(reinterpret_cast<char const*>(uc_result_lastName));
this->nAge = sqlite3_column_int(stmt, 2);
sqlite3_finalize(stmt);
std::cout << "\nLastname: " << strLastName << std::endl;
}