Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

143 lignes
4.9 KiB

  1. #include <cpphibernate/types.h>
  2. #include <cpphibernate/misc/print_container.h>
  3. #include <cpphibernate/driver/mariadb/classes/fields/field.h>
  4. #include <cpphibernate/driver/mariadb/classes/tables/table.h>
  5. #include <cppcore/misc/indent.h>
  6. using namespace ::cpphibernate;
  7. using namespace ::cpphibernate::mariadb;
  8. /* field_t */
  9. field_t::~field_t()
  10. { }
  11. std::ostream& field_t::print(std::ostream& os) const
  12. {
  13. using namespace ::cppcore;
  14. os << indent << '{'
  15. << incindent
  16. << indent << "\"id\": " << id << ","
  17. << indent << "\"value_id\": " << value_id << ","
  18. << indent << "\"real_value_id\": " << real_value_id << ","
  19. << indent << "\"value_is_nullable\": " << (value_is_nullable ? "true" : "false") << ","
  20. << indent << "\"value_is_pointer\": " << (value_is_pointer ? "true" : "false") << ","
  21. << indent << "\"value_is_container\": " << (value_is_container ? "true" : "false") << ","
  22. << indent << "\"value_is_auto_incremented\": " << (value_is_auto_incremented ? "true" : "false") << ","
  23. << indent << "\"table\": " << '"' << table.name << "\","
  24. << indent << "\"referenced_table\": " << (referenced_table
  25. ? std::string("\"") + referenced_table->name + "\""
  26. : "null") << ","
  27. << indent << "\"name\": \"" << name << "\","
  28. << indent << "\"type\": \"" << type << "\","
  29. << indent << "\"create_arguments\": \"" << create_arguments << "\","
  30. << indent << "\"convert_to_open\": \"" << convert_to_open << "\","
  31. << indent << "\"convert_to_close\": \"" << convert_to_close << "\","
  32. << indent << "\"convert_from_open\": \"" << convert_from_open << "\","
  33. << indent << "\"convert_from_close\": \"" << convert_from_close << "\","
  34. << indent << "\"attributes\": " << make_print_container(attributes, false)
  35. << decindent
  36. << indent << '}';
  37. return os;
  38. }
  39. void field_t::init()
  40. {
  41. /* conver_to_open */
  42. {
  43. std::ostringstream ss;
  44. for (auto& attrib : attributes)
  45. {
  46. switch(attrib)
  47. {
  48. case attribute_t::hex:
  49. ss << "HEX(";
  50. break;
  51. case attribute_t::compress:
  52. ss << "COMPRESS(";
  53. break;
  54. default:
  55. break;
  56. }
  57. }
  58. convert_to_open = ss.str();
  59. }
  60. /* convert_to_close */
  61. {
  62. std::ostringstream ss;
  63. for (auto& attrib : attributes)
  64. {
  65. switch(attrib)
  66. {
  67. case attribute_t::hex:
  68. case attribute_t::compress:
  69. ss << ')';
  70. break;
  71. default:
  72. break;
  73. }
  74. }
  75. convert_to_close = ss.str();
  76. }
  77. /* convert_from_open */
  78. {
  79. std::ostringstream ss;
  80. for (auto& attrib : attributes)
  81. {
  82. switch(attrib)
  83. {
  84. case attribute_t::hex:
  85. ss << "UNHEX(";
  86. break;
  87. case attribute_t::compress:
  88. ss << "UNCOMPRESS(";
  89. break;
  90. default:
  91. break;
  92. }
  93. }
  94. convert_from_open = ss.str();
  95. }
  96. /* convert_from_close */
  97. {
  98. std::ostringstream ss;
  99. for (auto& attrib : attributes)
  100. {
  101. switch(attrib)
  102. {
  103. case attribute_t::hex:
  104. case attribute_t::compress:
  105. ss << ')';
  106. break;
  107. default:
  108. break;
  109. }
  110. }
  111. convert_from_close = ss.str();
  112. }
  113. }
  114. #define throw_not_implemented(p_ret, p_name, ...) \
  115. p_ret field_t::p_name(__VA_ARGS__) const \
  116. { \
  117. throw ::cpphibernate::exception( \
  118. std::string("'") + table.name + "." + name + \
  119. "' does not implement the " #p_name "() method!"); \
  120. }
  121. throw_not_implemented(value_t, get, const data_context& context)
  122. throw_not_implemented(void, set, const data_context& context, const value_t& value)
  123. throw_not_implemented(bool, is_default, const data_context& context)
  124. throw_not_implemented(std::string, generate_value, ::cppmariadb::connection& connection)
  125. throw_not_implemented(value_t, foreign_create_update, const create_update_context& context)