field.hpp 1.7 KB

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