diff --git a/include/cpphibernate/driver/mariadb/mariadb.h b/include/cpphibernate/driver/mariadb/mariadb.h index 5bfcff8..c269622 100644 --- a/include/cpphibernate/driver/mariadb/mariadb.h +++ b/include/cpphibernate/driver/mariadb/mariadb.h @@ -12,14 +12,14 @@ beg_namespace_cpphibernate_driver_mariadb struct mariadb_driver_t { private: - ::cppmariadb::connection& _connection; + ::cppmariadb::connection* _connection; schema_t _schema; filter_t _filter; public: template mariadb_driver_t(T_schema&& p_schema, ::cppmariadb::connection& p_connection) - : _connection (p_connection) + : _connection (&p_connection) , _schema (make_schema(std::forward(p_schema))) { } @@ -27,7 +27,10 @@ beg_namespace_cpphibernate_driver_mariadb cpphibernate_moveable(mariadb_driver_t, default); inline const ::cppmariadb::connection& connection() const - { return _connection; } + { return *_connection; } + + inline void connection(::cppmariadb::connection& p_connection) + { _connection = &p_connection; } template inline void set_filter_inclusive(T_args&&... args) @@ -43,8 +46,8 @@ beg_namespace_cpphibernate_driver_mariadb protected: inline void init_impl(bool recreate) const { - transaction_lock trans(_connection); - _schema.init(init_context(_schema, _connection, recreate)); + transaction_lock trans(*_connection); + _schema.init(init_context(_schema, *_connection, recreate)); trans.commit(); } @@ -52,7 +55,7 @@ beg_namespace_cpphibernate_driver_mariadb inline void create_impl(T_dataset& dataset) const { create_update_impl_t::apply( - create_update_context(dataset, _schema, _connection, _filter, false)); + create_update_context(dataset, _schema, *_connection, _filter, false)); } template @@ -63,12 +66,12 @@ beg_namespace_cpphibernate_driver_mariadb auto dataset_id = misc::get_type_id(hana::type_c); auto& table = _schema.table(dataset_id); - auto context = make_read_context(dataset, _schema, _connection, _filter); - context.where = build_where(_schema, modifiers).query(_connection); - context.limit = build_limit(modifiers).query(_connection); - context.order_by = build_order_by(_schema, modifiers).query(_connection); + auto context = make_read_context(dataset, _schema, *_connection, _filter); + context.where = build_where(_schema, modifiers).query(*_connection); + context.limit = build_limit(modifiers).query(*_connection); + context.order_by = build_order_by(_schema, modifiers).query(*_connection); - transaction_lock trans(_connection); + transaction_lock trans(*_connection); table.read(context); trans.commit(); } @@ -77,7 +80,7 @@ beg_namespace_cpphibernate_driver_mariadb inline void update_impl(T_dataset& dataset) const { create_update_impl_t::apply( - create_update_context(dataset, _schema, _connection, _filter, true)); + create_update_context(dataset, _schema, *_connection, _filter, true)); } template @@ -89,7 +92,7 @@ beg_namespace_cpphibernate_driver_mariadb auto dataset_id = misc::get_type_id(hana::type_c); auto& table = _schema.table(dataset_id); - destroy_context context(dataset, _schema, _connection); + destroy_context context(dataset, _schema, *_connection); context.where = table.get_where_primary_key(context); destroy_impl_t::apply(context);