log
This commit is contained in:
28
Database.cpp
28
Database.cpp
@ -11,5 +11,33 @@ DatabaseHandle::~DatabaseHandle() {
|
||||
sqlite3_close(dbh);
|
||||
}
|
||||
|
||||
PreparedStatement DatabaseHandle::prepareStatement(const std::string& statement) {
|
||||
return PreparedStatement(dbh, statement);
|
||||
}
|
||||
|
||||
|
||||
PreparedStatement::PreparedStatement(sqlite3 *dbh, const std::string& statement) {
|
||||
const char *tail;
|
||||
int rc = sqlite3_prepare_v2(dbh, statement.c_str(), -1, &stmt, &tail);
|
||||
if (SQLITE_OK != rc)
|
||||
throw DatabaseError();
|
||||
}
|
||||
|
||||
PreparedStatement::~PreparedStatement() {
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
result_t PreparedStatement::next() {
|
||||
int rc = sqlite3_step(stmt);
|
||||
int ncol = sqlite3_column_count(stmt);
|
||||
result_t result;
|
||||
if (SQLITE_ROW == rc) {
|
||||
for (int i = 0; i < ncol; i++) {
|
||||
string key = sqlite3_column_name(stmt, i);
|
||||
string value = string(reinterpret_cast<const char*>(sqlite3_column_text(stmt, i)));
|
||||
result.insert(pair<string, string>(key, value));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user