61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
#include "catch2/catch_test_macros.hpp"
|
|
|
|
#include "matador/query/query.hpp"
|
|
#include "matador/query/sequence_pk_generator.hpp"
|
|
|
|
#include "SequenceFixture.hpp"
|
|
|
|
using namespace matador::query;
|
|
using namespace matador::test;
|
|
|
|
TEST_CASE_METHOD(SequenceFixture, "test create and drop sequence", "[sequence][create][drop]") {
|
|
auto result = create()
|
|
.sequence("person_seq")
|
|
.execute(db);
|
|
REQUIRE(result.is_ok());
|
|
|
|
sequences_to_drop.emplace("person_seq");
|
|
|
|
auto next_id = select()
|
|
.nextval("person_seq")
|
|
.fetch_value<uint32_t>(db);
|
|
|
|
REQUIRE(next_id.is_ok());
|
|
REQUIRE(*next_id == 1);
|
|
|
|
auto curr_id = select()
|
|
.currval("person_seq")
|
|
.fetch_value<uint32_t>(db);
|
|
|
|
REQUIRE(curr_id.is_ok());
|
|
REQUIRE(*curr_id == 1);
|
|
|
|
result = drop()
|
|
.sequence("person_seq")
|
|
.execute(db);
|
|
REQUIRE(result.is_ok());
|
|
}
|
|
|
|
TEST_CASE_METHOD(SequenceFixture, "Test nextval and currval through sequence pk generator", "[sequence][nextval][currval]") {
|
|
auto result = create()
|
|
.sequence("person_seq")
|
|
.execute(db);
|
|
REQUIRE(result.is_ok());
|
|
|
|
sequences_to_drop.emplace("person_seq");
|
|
|
|
sequence_pk_generator generator("person_seq");
|
|
|
|
auto pk_result = generator.next_id(db);
|
|
REQUIRE(pk_result.is_ok());
|
|
REQUIRE(*pk_result == 1);
|
|
|
|
pk_result = generator.current_id(db);
|
|
REQUIRE(pk_result.is_ok());
|
|
REQUIRE(*pk_result == 1);
|
|
|
|
result = drop()
|
|
.sequence("person_seq")
|
|
.execute(db);
|
|
REQUIRE(result.is_ok());
|
|
} |