class SQLStatement {
public:
+ enum class StepResult : int {
+ DONE,
+ ROW,
+ ERROR,
+ };
+
explicit SQLStatement(SQLConnection* sql_conn) : sql_conn_(sql_conn) {}
virtual ~SQLStatement() = default;
- virtual bool Step() = 0;
+ virtual StepResult Step() = 0;
virtual bool BindInt(int pos, int val) = 0;
virtual bool BindString(int pos, const std::string& val) = 0;
LOG(ERROR) << "sqlite3_finalize() failed: " << GetErrorMessage();
}
-bool SQLiteStatement::Step() {
+SQLStatement::StepResult SQLiteStatement::Step() {
int r = sqlite3_step(stmt_);
if (r != SQLITE_ROW && r != SQLITE_DONE) {
LOG(ERROR) << "sqlite3_step() failed: " << GetErrorMessage();
sql_conn_->SetErrorCode(r);
- return false;
+ return SQLStatement::StepResult::ERROR;
}
- return true;
+ SQLStatement::StepResult res;
+ if (r == SQLITE_ROW) {
+ res = SQLStatement::StepResult::ROW;
+ } else if (r == SQLITE_DONE) {
+ res = SQLStatement::StepResult::DONE;
+ } else {
+ LOG(ERROR) << "Unexpected sqlite3 result code: " << r;
+ res = SQLStatement::StepResult::ERROR;
+ }
+ return res;
}
bool SQLiteStatement::BindInt(int pos, int val) {
SQLiteStatement(const SQLiteStatement&) = delete;
SQLiteStatement& operator=(const SQLiteStatement&) = delete;
- bool Step() override;
+ SQLStatement::StepResult Step() override;
bool BindInt(int pos, int val) override;
bool BindString(int pos, const std::string& val) override;
"SELECT COUNT(name) FROM capability WHERE pkgid='org.tizen.rollbacktest'";
std::shared_ptr<SQLStatement> stmt =
sql_conn->PrepareStatement(kQueryRollbackValidation);
- ASSERT_TRUE(stmt->Step());
+ ASSERT_EQ(stmt->Step(), SQLStatement::StepResult::DONE);
int count = stmt->GetColumnInt(0);
ASSERT_EQ(count, 0);
}