40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#include "catch2/catch_test_macros.hpp"
|
|
|
|
#include "matador/query/criteria.hpp"
|
|
#include "matador/query/expression/expression_operators.hpp"
|
|
#include "matador/query/query.hpp"
|
|
#include "matador/query/table_column.hpp"
|
|
|
|
#include "TableSequenceFixture.hpp"
|
|
|
|
using namespace matador::query;
|
|
using namespace matador::test;
|
|
|
|
TEST_CASE_METHOD(TableSequenceFixture, "test create and drop table sequence", "[table_sequence][create][drop]") {
|
|
const auto next_id_col = "next_id"_col;
|
|
auto result = query::query::insert()
|
|
.into(sequence_table_name, { "name", next_id_col})
|
|
.values({ "test_seq", 1 })
|
|
.execute(db);
|
|
REQUIRE(result);
|
|
REQUIRE(result->affected_rows == 1);
|
|
|
|
table_column exp(next_id_col - 1);
|
|
auto id_result = query::query::update(sequence_table_name)
|
|
.set(next_id_col, next_id_col + 1)
|
|
.where("name"_col == "test_seq")
|
|
.returning((next_id_col - 1).as("id"))
|
|
.fetch_value<int64_t>(db);
|
|
|
|
REQUIRE(id_result);
|
|
REQUIRE(id_result->has_value());
|
|
REQUIRE(id_result->value() == 1);
|
|
|
|
id_result = query::query::select({next_id_col})
|
|
.from(sequence_table_name)
|
|
.where("name"_col == "test_seq")
|
|
.fetch_value<int64_t>(db);
|
|
REQUIRE(id_result);
|
|
REQUIRE(id_result->has_value());
|
|
REQUIRE(id_result->value() == 2);
|
|
} |