field.ipp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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_FIELD_IPP
  8. #define BOOST_MYSQL_IMPL_FIELD_IPP
  9. #pragma once
  10. #include <boost/mysql/field.hpp>
  11. #include <ostream>
  12. namespace boost {
  13. namespace mysql {
  14. namespace detail {
  15. inline blob to_blob(blob_view v) { return blob(v.data(), v.data() + v.size()); }
  16. } // namespace detail
  17. } // namespace mysql
  18. } // namespace boost
  19. void boost::mysql::field::from_view(const field_view& fv)
  20. {
  21. switch (fv.kind())
  22. {
  23. case field_kind::null: repr_.data.emplace<detail::field_impl::null_t>(); break;
  24. case field_kind::int64: repr_.data.emplace<std::int64_t>(fv.get_int64()); break;
  25. case field_kind::uint64: repr_.data.emplace<std::uint64_t>(fv.get_uint64()); break;
  26. case field_kind::string: repr_.data.emplace<std::string>(fv.get_string()); break;
  27. case field_kind::blob: repr_.data.emplace<blob>(detail::to_blob(fv.get_blob())); break;
  28. case field_kind::float_: repr_.data.emplace<float>(fv.get_float()); break;
  29. case field_kind::double_: repr_.data.emplace<double>(fv.get_double()); break;
  30. case field_kind::date: repr_.data.emplace<date>(fv.get_date()); break;
  31. case field_kind::datetime: repr_.data.emplace<datetime>(fv.get_datetime()); break;
  32. case field_kind::time: repr_.data.emplace<time>(fv.get_time()); break;
  33. }
  34. }
  35. std::ostream& boost::mysql::operator<<(std::ostream& os, const field& value)
  36. {
  37. return os << field_view(value);
  38. }
  39. #endif