meta_check_context.ipp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MYSQL_IMPL_META_CHECK_CONTEXT_IPP
  8. #define BOOST_MYSQL_IMPL_META_CHECK_CONTEXT_IPP
  9. #pragma once
  10. #include <boost/mysql/detail/typing/meta_check_context.hpp>
  11. void boost::mysql::detail::meta_check_context::add_field_absent_error()
  12. {
  13. auto& stream = add_error();
  14. stream << "Field ";
  15. insert_field_name(stream);
  16. if (has_field_names(name_table_))
  17. {
  18. stream << " is not present in the data returned by the server";
  19. }
  20. else
  21. {
  22. stream << " can't be mapped: there are more fields in your C++ data type than in your query";
  23. }
  24. }
  25. void boost::mysql::detail::meta_check_context::add_type_mismatch_error(const char* cpp_type_name)
  26. {
  27. auto& stream = add_error();
  28. stream << "Incompatible types for field ";
  29. insert_field_name(stream);
  30. stream << ": C++ type '" << cpp_type_name << "' is not compatible with DB type '"
  31. << column_type_to_str(current_meta()) << "'";
  32. }
  33. void boost::mysql::detail::meta_check_context::add_nullability_error()
  34. {
  35. auto& stream = add_error();
  36. stream << "NULL checks failed for field ";
  37. insert_field_name(stream);
  38. stream << ": the database type may be NULL, but the C++ type cannot. Use std::optional<T> or "
  39. "boost::optional<T>";
  40. }
  41. boost::mysql::error_code boost::mysql::detail::meta_check_context::check_errors(diagnostics& diag) const
  42. {
  43. if (errors_ != nullptr)
  44. {
  45. access::get_impl(diag).assign_client(errors_->str());
  46. return client_errc::metadata_check_failed;
  47. }
  48. return error_code();
  49. }
  50. #endif