|
- #include <cpphibernate/types.h>
- #include <cpphibernate/misc/print_container.h>
- #include <cpphibernate/driver/mariadb/classes/fields/field.h>
- #include <cpphibernate/driver/mariadb/classes/tables/table.h>
-
- #include <cppcore/misc/indent.h>
-
- using namespace ::cpphibernate;
- using namespace ::cpphibernate::mariadb;
-
- /* field_t */
-
- field_t::~field_t()
- { }
-
- std::ostream& field_t::print(std::ostream& os) const
- {
- using namespace ::cppcore;
-
- os << indent << '{'
- << incindent
-
- << indent << "\"id\": " << id << ","
- << indent << "\"value_id\": " << value_id << ","
- << indent << "\"real_value_id\": " << real_value_id << ","
- << indent << "\"value_is_nullable\": " << (value_is_nullable ? "true" : "false") << ","
- << indent << "\"value_is_pointer\": " << (value_is_pointer ? "true" : "false") << ","
- << indent << "\"value_is_container\": " << (value_is_container ? "true" : "false") << ","
- << indent << "\"value_is_auto_incremented\": " << (value_is_auto_incremented ? "true" : "false") << ","
- << indent << "\"table\": " << '"' << table.name << "\","
- << indent << "\"referenced_table\": " << (referenced_table
- ? std::string("\"") + referenced_table->name + "\""
- : "null") << ","
- << indent << "\"name\": \"" << name << "\","
- << indent << "\"type\": \"" << type << "\","
- << indent << "\"create_arguments\": \"" << create_arguments << "\","
-
- << indent << "\"convert_to_open\": \"" << convert_to_open << "\","
- << indent << "\"convert_to_close\": \"" << convert_to_close << "\","
- << indent << "\"convert_from_open\": \"" << convert_from_open << "\","
- << indent << "\"convert_from_close\": \"" << convert_from_close << "\","
-
- << indent << "\"attributes\": " << make_print_container(attributes, false)
-
- << decindent
- << indent << '}';
-
- return os;
- }
-
- void field_t::init()
- {
- /* conver_to_open */
- {
- std::ostringstream ss;
- for (auto& attrib : attributes)
- {
- switch(attrib)
- {
- case attribute_t::hex:
- ss << "HEX(";
- break;
- case attribute_t::compress:
- ss << "COMPRESS(";
- break;
- default:
- break;
- }
- }
- convert_to_open = ss.str();
- }
-
- /* convert_to_close */
- {
- std::ostringstream ss;
- for (auto& attrib : attributes)
- {
- switch(attrib)
- {
- case attribute_t::hex:
- case attribute_t::compress:
- ss << ')';
- break;
- default:
- break;
- }
- }
- convert_to_close = ss.str();
- }
-
- /* convert_from_open */
- {
- std::ostringstream ss;
- for (auto& attrib : attributes)
- {
- switch(attrib)
- {
- case attribute_t::hex:
- ss << "UNHEX(";
- break;
- case attribute_t::compress:
- ss << "UNCOMPRESS(";
- break;
- default:
- break;
- }
- }
- convert_from_open = ss.str();
- }
-
- /* convert_from_close */
- {
- std::ostringstream ss;
- for (auto& attrib : attributes)
- {
- switch(attrib)
- {
- case attribute_t::hex:
- case attribute_t::compress:
- ss << ')';
- break;
- default:
- break;
- }
- }
- convert_from_close = ss.str();
- }
- }
-
- #define throw_not_implemented(p_ret, p_name, ...) \
- p_ret field_t::p_name(__VA_ARGS__) const \
- { \
- throw ::cpphibernate::exception( \
- std::string("'") + table.name + "." + name + \
- "' does not implement the " #p_name "() method!"); \
- }
-
- throw_not_implemented(value_t, get, const data_context& context)
- throw_not_implemented(void, set, const data_context& context, const value_t& value)
- throw_not_implemented(bool, is_default, const data_context& context)
- throw_not_implemented(std::string, generate_value, ::cppmariadb::connection& connection)
- throw_not_implemented(value_t, foreign_create_update, const create_update_context& context)
|