From 42501c339fef8c99abf0e9f26885a10181b768e8 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 6 Jul 2022 09:44:02 +0200 Subject: [PATCH] Added owner support for the DatabaseConnection. --- modules/database/database.cpp | 5 +++++ modules/database/database_connection.cpp | 7 +++++++ modules/database/database_connection.h | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/modules/database/database.cpp b/modules/database/database.cpp index b55ead41a..4c86f73ff 100644 --- a/modules/database/database.cpp +++ b/modules/database/database.cpp @@ -17,6 +17,11 @@ Ref Database::get_connection() { } Ref Database::_allocate_connection() { + //Ref dbc; + //dbc.instance(); + //dbc->set_owner(this); //if needed + //return dbc; + return Ref(); } diff --git a/modules/database/database_connection.cpp b/modules/database/database_connection.cpp index bc9d0ce2a..ccff67fca 100644 --- a/modules/database/database_connection.cpp +++ b/modules/database/database_connection.cpp @@ -29,10 +29,16 @@ String DatabaseConnection::escape(const String &str) { void DatabaseConnection::escape_to(const String &str, String *to) { } +Ref DatabaseConnection::get_owner() { + return Ref(_owner); +} + DatabaseConnection::DatabaseConnection() { + _owner = nullptr; } DatabaseConnection::~DatabaseConnection() { + _owner = nullptr; } void DatabaseConnection::_bind_methods() { @@ -42,4 +48,5 @@ void DatabaseConnection::_bind_methods() { ClassDB::bind_method(D_METHOD("get_query_builder"), &DatabaseConnection::get_query_builder); ClassDB::bind_method(D_METHOD("get_table_builder"), &DatabaseConnection::get_table_builder); ClassDB::bind_method(D_METHOD("escape", "str"), &DatabaseConnection::escape); + ClassDB::bind_method(D_METHOD("get_owner"), &DatabaseConnection::get_owner); } diff --git a/modules/database/database_connection.h b/modules/database/database_connection.h index 80e247496..16e890152 100644 --- a/modules/database/database_connection.h +++ b/modules/database/database_connection.h @@ -8,6 +8,7 @@ class QueryBuilder; class TableBuilder; class QueryResult; +class Database; class DatabaseConnection : public Reference { GDCLASS(DatabaseConnection, Reference); @@ -23,11 +24,18 @@ public: virtual String escape(const String &str); virtual void escape_to(const String &str, String *to); + Ref get_owner(); + void set_owner(Database *owner); + DatabaseConnection(); ~DatabaseConnection(); protected: static void _bind_methods(); + + //"WeakRef" + //Note: Set this to null if the owner Database gets destroyed! + Database *_owner; }; #endif