pk generator progress and sequence test progress
This commit is contained in:
@@ -45,6 +45,8 @@ public:
|
||||
private:
|
||||
[[nodiscard]] static std::string generate_statement_name(const sql::query_context &query) ;
|
||||
|
||||
utils::result<sql::execute_result, utils::error> execute(const std::string &stmt) const;
|
||||
|
||||
private:
|
||||
PGconn *conn_{nullptr};
|
||||
|
||||
|
||||
@@ -129,6 +129,20 @@ std::string postgres_connection::generate_statement_name(const sql::query_contex
|
||||
return name.str();
|
||||
}
|
||||
|
||||
utils::result<sql::execute_result, utils::error> postgres_connection::execute(const std::string& stmt) const {
|
||||
PGresult *res = PQexec(conn_, stmt.c_str());
|
||||
|
||||
if (const auto status = PQresultStatus(res); status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
|
||||
return utils::failure(make_error(sql::error_code::FAILURE, res, conn_, "Failed to execute", stmt));
|
||||
}
|
||||
|
||||
const size_t affected_rows = utils::to<size_t>(PQcmdTuples(res));
|
||||
|
||||
PQclear(res);
|
||||
|
||||
return utils::ok(sql::execute_result{affected_rows});
|
||||
}
|
||||
|
||||
utils::result<std::unique_ptr<sql::statement_impl>, utils::error> postgres_connection::prepare(const sql::query_context &context) {
|
||||
auto statement_name = generate_statement_name(context);
|
||||
|
||||
@@ -143,9 +157,7 @@ utils::result<std::unique_ptr<sql::statement_impl>, utils::error> postgres_conne
|
||||
}
|
||||
|
||||
utils::result<sql::execute_result, utils::error> postgres_connection::execute(const sql::query_context &context) {
|
||||
if (context.command == sql::sql_command::Insert) {
|
||||
// handle insert command with the primary key generator strategy
|
||||
}
|
||||
return execute(context.sql);
|
||||
PGresult *res = PQexec(conn_, context.sql.c_str());
|
||||
|
||||
if (const auto status = PQresultStatus(res); status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
|
||||
@@ -299,7 +311,17 @@ utils::result<bool, utils::error> postgres_connection::exists(const std::string
|
||||
}
|
||||
|
||||
utils::result<bool, utils::error> postgres_connection::sequence_exists(const std::string& schema_name, const std::string& sequence_name) {
|
||||
return utils::ok(false);
|
||||
const std::string sql{"SELECT to_regclass('" + schema_name + "." + sequence_name + "')"};
|
||||
PGresult* res = PQexec(conn_, sql.c_str());
|
||||
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
|
||||
return utils::failure(make_error(sql::error_code::SEQUENCE_EXISTS_FAILED, res, conn_, "Failed check if sequence exists", sql));
|
||||
}
|
||||
|
||||
const bool exists = PQgetisnull(res, 0, 0) ? false : true;
|
||||
PQclear(res);
|
||||
|
||||
return utils::ok(exists);
|
||||
}
|
||||
|
||||
std::string postgres_connection::to_escaped_string(const utils::blob_type_t &value) const {
|
||||
|
||||
@@ -34,8 +34,8 @@ set(TEST_SOURCES
|
||||
../../../test/utils/record_printer.hpp
|
||||
../../../test/utils/record_printer.cpp
|
||||
../../../test/models/model_metas.hpp
|
||||
../../../test/backends/SequenceFixture.hpp
|
||||
../../../test/backends/SequenceFixture.cpp
|
||||
../../../test/backends/SequenceFixture.hpp
|
||||
../../../test/backends/SequenceFixture.cpp
|
||||
../../../test/backends/SequenceTest.cpp
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user