File indexing completed on 2025-01-18 09:42:38
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_DETAIL_TYPING_META_CHECK_CONTEXT_HPP
0009 #define BOOST_MYSQL_DETAIL_TYPING_META_CHECK_CONTEXT_HPP
0010
0011 #include <boost/mysql/client_errc.hpp>
0012 #include <boost/mysql/column_type.hpp>
0013 #include <boost/mysql/diagnostics.hpp>
0014 #include <boost/mysql/error_code.hpp>
0015 #include <boost/mysql/metadata.hpp>
0016 #include <boost/mysql/metadata_collection_view.hpp>
0017 #include <boost/mysql/string_view.hpp>
0018
0019 #include <boost/mysql/detail/access.hpp>
0020 #include <boost/mysql/detail/config.hpp>
0021 #include <boost/mysql/detail/typing/pos_map.hpp>
0022
0023 #include <memory>
0024 #include <sstream>
0025
0026 namespace boost {
0027 namespace mysql {
0028 namespace detail {
0029
0030 inline const char* column_type_to_str(const metadata& meta) noexcept
0031 {
0032 switch (meta.type())
0033 {
0034 case column_type::tinyint: return meta.is_unsigned() ? "TINYINT UNSIGNED" : "TINYINT";
0035 case column_type::smallint: return meta.is_unsigned() ? "SMALLINT UNSIGNED" : "SMALLINT";
0036 case column_type::mediumint: return meta.is_unsigned() ? "MEDIUMINT UNSIGNED" : "MEDIUMINT";
0037 case column_type::int_: return meta.is_unsigned() ? "INT UNSIGNED" : "INT";
0038 case column_type::bigint: return meta.is_unsigned() ? "BIGINT UNSIGNED" : "BIGINT";
0039 case column_type::float_: return "FLOAT";
0040 case column_type::double_: return "DOUBLE";
0041 case column_type::decimal: return "DECIMAL";
0042 case column_type::bit: return "BIT";
0043 case column_type::year: return "YEAR";
0044 case column_type::time: return "TIME";
0045 case column_type::date: return "DATE";
0046 case column_type::datetime: return "DATETIME";
0047 case column_type::timestamp: return "TIMESTAMP";
0048 case column_type::char_: return "CHAR";
0049 case column_type::varchar: return "VARCHAR";
0050 case column_type::binary: return "BINARY";
0051 case column_type::varbinary: return "VARBINARY";
0052 case column_type::text: return "TEXT";
0053 case column_type::blob: return "BLOB";
0054 case column_type::enum_: return "ENUM";
0055 case column_type::set: return "SET";
0056 case column_type::json: return "JSON";
0057 case column_type::geometry: return "GEOMETRY";
0058 default: return "<unknown column type>";
0059 }
0060 }
0061
0062 class meta_check_context
0063 {
0064 std::unique_ptr<std::ostringstream> errors_;
0065 std::size_t current_index_{};
0066 span<const std::size_t> pos_map_;
0067 name_table_t name_table_;
0068 metadata_collection_view meta_{};
0069 bool nullability_checked_{};
0070
0071 std::ostringstream& add_error()
0072 {
0073 if (!errors_)
0074 errors_.reset(new std::ostringstream);
0075 else
0076 *errors_ << '\n';
0077 return *errors_;
0078 }
0079
0080 void insert_field_name(std::ostringstream& os)
0081 {
0082 if (has_field_names(name_table_))
0083 os << "'" << name_table_[current_index_] << "'";
0084 else
0085 os << "in position " << current_index_;
0086 }
0087
0088 public:
0089 meta_check_context(
0090 span<const std::size_t> pos_map,
0091 name_table_t name_table,
0092 metadata_collection_view meta
0093 ) noexcept
0094 : pos_map_(pos_map), name_table_(name_table), meta_(meta)
0095 {
0096 }
0097
0098
0099 const metadata& current_meta() const noexcept { return map_metadata(pos_map_, current_index_, meta_); }
0100 bool is_current_field_absent() const noexcept { return pos_map_[current_index_] == pos_absent; }
0101
0102
0103 void advance() noexcept
0104 {
0105 nullability_checked_ = false;
0106 ++current_index_;
0107 }
0108
0109
0110 void set_nullability_checked() noexcept { nullability_checked_ = true; }
0111 bool nullability_checked() const noexcept { return nullability_checked_; }
0112
0113
0114 BOOST_MYSQL_DECL
0115 void add_field_absent_error();
0116
0117 BOOST_MYSQL_DECL
0118 void add_type_mismatch_error(const char* cpp_type_name);
0119
0120 BOOST_MYSQL_DECL
0121 void add_nullability_error();
0122
0123 BOOST_MYSQL_DECL
0124 error_code check_errors(diagnostics& diag) const;
0125 };
0126
0127 }
0128 }
0129 }
0130
0131 #ifdef BOOST_MYSQL_HEADER_ONLY
0132 #include <boost/mysql/impl/meta_check_context.ipp>
0133 #endif
0134
0135 #endif