added test for date and time, sql read and write functionality

This commit is contained in:
2026-01-06 22:23:50 +01:00
parent 0c6b5a0a93
commit c48bd4f9d6
17 changed files with 516 additions and 360 deletions
+46 -42
View File
@@ -9,104 +9,108 @@
#include "matador/utils/string.hpp"
namespace matador::query {
attribute_string_writer::attribute_string_writer(const sql::dialect &d, const std::optional<std::reference_wrapper<const sql::connection_impl>> conn)
attribute_string_writer::attribute_string_writer(const sql::dialect &d,
const std::optional<std::reference_wrapper<const
sql::connection_impl> > conn)
: dialect_(d)
, conn_(conn) {}
const sql::dialect& attribute_string_writer::dialect() const {
return dialect_;
, conn_(conn) {
}
void attribute_string_writer::write_value(size_t /*pos*/, const int8_t& x ) {
result_ = std::to_string(x) ;
const sql::dialect &attribute_string_writer::dialect() const {
return dialect_;
}
void attribute_string_writer::write_value(size_t /*pos*/, const int16_t& x ) {
result_ = std::to_string(x) ;
void attribute_string_writer::write_value(size_t /*pos*/, const int8_t &x) {
result_ = std::to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const int32_t& x ) {
result_ = std::to_string(x) ;
void attribute_string_writer::write_value(size_t /*pos*/, const int16_t &x) {
result_ = std::to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const int64_t& x ) {
result_ = std::to_string(x) ;
void attribute_string_writer::write_value(size_t /*pos*/, const int32_t &x) {
result_ = std::to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const uint8_t& x ) {
result_ = std::to_string(x) ;
void attribute_string_writer::write_value(size_t /*pos*/, const int64_t &x) {
result_ = std::to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const uint16_t& x ) {
result_ = std::to_string(x) ;
void attribute_string_writer::write_value(size_t /*pos*/, const uint8_t &x) {
result_ = std::to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const uint32_t& x ) {
result_ = std::to_string(x) ;
void attribute_string_writer::write_value(size_t /*pos*/, const uint16_t &x) {
result_ = std::to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const uint64_t& x ) {
result_ = std::to_string(x) ;
void attribute_string_writer::write_value(size_t /*pos*/, const uint32_t &x) {
result_ = std::to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const bool& x ) {
// result_ = "'" + conn_->dialect().prepare_literal(x ? "true" : "false") + "'";
void attribute_string_writer::write_value(size_t /*pos*/, const uint64_t &x) {
result_ = std::to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const bool &x) {
// result_ = "'" + conn_->dialect().prepare_literal(x ? "true" : "false") + "'";
result_ = dialect_.to_string(x);
}
void attribute_string_writer::write_value(size_t /*pos*/, const float& x ) {
void attribute_string_writer::write_value(size_t /*pos*/, const float &x) {
if (const auto res = utils::to<std::string>(x); !res.is_error()) {
result_ = *res;
}
}
void attribute_string_writer::write_value(size_t /*pos*/, const double& x ) {
void attribute_string_writer::write_value(size_t /*pos*/, const double &x) {
if (const auto res = utils::to<std::string>(x); !res.is_error()) {
result_ = *res;
}
}
void attribute_string_writer::write_value(size_t /*pos*/, const utils::date_type_t& /*x*/ ) {
// result_ = "'" + dialect_.prepare_literal(utils::to_string(x)) + "'";
void attribute_string_writer::write_value(size_t /*pos*/, const utils::date_type_t &x) {
result_ = "'" + dialect_.prepare_literal(utils::to_string(x)) + "'";
}
void attribute_string_writer::write_value(size_t /*pos*/, const utils::time_type_t& /*x*/ ) {
// result_ = "'" + dialect_.prepare_literal(utils::to_string(x, "%F %T.%f")) + "'";
void attribute_string_writer::write_value(size_t /*pos*/, const utils::time_type_t &x) {
result_ = "'" + dialect_.prepare_literal(utils::to_string(x)) + "'";
}
void attribute_string_writer::write_value(size_t /*pos*/, const utils::timestamp &/*x*/) {
}
void attribute_string_writer::write_value(size_t pos, const char* x ) {
write_value(pos, std::string(x) );
void attribute_string_writer::write_value(size_t pos, const char *x) {
write_value(pos, std::string(x));
}
void attribute_string_writer::write_value(size_t pos, const char* x, size_t /*size*/) {
write_value(pos, std::string(x) );
void attribute_string_writer::write_value(size_t pos, const char *x, size_t /*size*/) {
write_value(pos, std::string(x));
}
void attribute_string_writer::write_value(size_t /*pos*/, const std::string& x ) {
void attribute_string_writer::write_value(size_t /*pos*/, const std::string &x) {
result_ = "'" + dialect_.prepare_literal(x) + "'";
}
void attribute_string_writer::write_value(size_t /*pos*/, const std::string& x, size_t /*size*/) {
void attribute_string_writer::write_value(size_t /*pos*/, const std::string &x, size_t /*size*/) {
result_ = "'" + dialect_.prepare_literal(x) + "'";
}
void attribute_string_writer::write_value(size_t /*pos*/, const utils::blob& x ) {
void attribute_string_writer::write_value(size_t /*pos*/, const utils::blob &x) {
// "This is a binary Data string" as binary data:
// MySQL: X'5468697320697320612062616E617279204461746120737472696E67'
// Postgres: '\\x5468697320697320612062616E617279204461746120737472696E67'
// MSSQL: 0x5468697320697320612062616E617279204461746120737472696E67
// Sqlite: X'5468697320697320612062616E617279204461746120737472696E67'
if (conn_.has_value()) {
result_ = dialect_.token_at(sql::dialect_token::BeginBinaryData) + conn_.value().get().to_escaped_string(x) + dialect_.token_at(sql::dialect_token::EndBinaryData);
result_ = dialect_.token_at(sql::dialect_token::BeginBinaryData) + conn_.value().get().to_escaped_string(x) +
dialect_.token_at(sql::dialect_token::EndBinaryData);
} else {
result_ = dialect_.token_at(sql::dialect_token::BeginBinaryData) + dialect_.to_escaped_string(x) + dialect_.token_at(sql::dialect_token::EndBinaryData);
result_ = dialect_.token_at(sql::dialect_token::BeginBinaryData) + dialect_.to_escaped_string(x) + dialect_.
token_at(sql::dialect_token::EndBinaryData);
}
}
void attribute_string_writer::write_value(size_t /*pos*/, const utils::value &/*x*/, size_t /*size*/) {}
}
void attribute_string_writer::write_value(size_t /*pos*/, const utils::value &/*x*/, size_t /*size*/) {
}
}
+23 -25
View File
@@ -3,49 +3,47 @@
#include "matador/sql/interface/query_result_reader.hpp"
namespace matador::sql {
detail::pk_reader::pk_reader(query_result_reader &reader)
: reader_(reader) {}
: reader_(reader) {
}
query_result_impl::query_result_impl(std::unique_ptr<query_result_reader> &&reader, std::vector<object::attribute> &&prototype, const size_t column_index)
query_result_impl::query_result_impl(std::unique_ptr<query_result_reader> &&reader,
std::vector<object::attribute> &&prototype,
const size_t column_index)
: column_index_(column_index)
, prototype_(std::move(prototype))
, reader_(std::move(reader))
, pk_reader_(*reader_)
{}
, prototype_(std::move(prototype))
, reader_(std::move(reader))
, pk_reader_(*reader_) {
}
query_result_impl::query_result_impl(std::unique_ptr<query_result_reader> &&reader, const std::vector<object::attribute> &prototype, const size_t column_index)
query_result_impl::query_result_impl(std::unique_ptr<query_result_reader> &&reader,
const std::vector<object::attribute> &prototype,
const size_t column_index)
: column_index_(column_index)
, prototype_(prototype)
, reader_(std::move(reader))
, pk_reader_(*reader_)
{}
, prototype_(prototype)
, reader_(std::move(reader))
, pk_reader_(*reader_) {
}
void query_result_impl::on_revision(const char *id, uint64_t &rev)
{
void query_result_impl::on_revision(const char *id, uint64_t &rev) {
utils::data_type_traits<uint64_t>::read_value(*reader_, id, column_index_++, rev);
reader_->read_value(id, column_index_++, rev);
}
void query_result_impl::on_attribute(const char *id, char *value, const utils::field_attributes &attr)
{
utils::data_type_traits<char*>::read_value(*reader_, id, column_index_++, value, attr.size());
void query_result_impl::on_attribute(const char *id, char *value, const utils::field_attributes &attr) {
utils::data_type_traits<char *>::read_value(*reader_, id, column_index_++, value, attr.size());
}
void query_result_impl::on_attribute(const char *id, std::string &value, const utils::field_attributes &attr)
{
void query_result_impl::on_attribute(const char *id, std::string &value, const utils::field_attributes &attr) {
utils::data_type_traits<std::string>::read_value(*reader_, id, column_index_++, value, attr.size());
}
void
query_result_impl::on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr)
{
query_result_impl::on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr) {
reader_->read_value(id, column_index_++, val, attr.size());
}
const std::vector<object::attribute>& query_result_impl::prototype() const
{
const std::vector<object::attribute> &query_result_impl::prototype() const {
return prototype_;
}
}
}
+6 -5
View File
@@ -61,15 +61,16 @@ void value_extractor::write_value(size_t /*pos*/, const double &x) {
values_.emplace_back(x);
}
void value_extractor::write_value(size_t /*pos*/, const utils::date_type_t &/*x*/) {
// values_.emplace_back(x);
void value_extractor::write_value(size_t /*pos*/, const utils::date_type_t &x) {
values_.emplace_back(x);
}
void value_extractor::write_value(size_t /*pos*/, const utils::time_type_t &/*x*/) {
// values_.emplace_back(x);
void value_extractor::write_value(size_t /*pos*/, const utils::time_type_t &x) {
values_.emplace_back(x);
}
void value_extractor::write_value(size_t /*pos*/, const utils::timestamp &/*x*/) {
void value_extractor::write_value(size_t /*pos*/, const utils::timestamp &x) {
values_.emplace_back(x);
}
void value_extractor::write_value(size_t /*pos*/, const char *x) {