Added owner support for the DatabaseConnection.

This commit is contained in:
Relintai 2022-07-06 09:44:02 +02:00
parent be6ec3ee61
commit 42501c339f
3 changed files with 20 additions and 0 deletions

View File

@ -17,6 +17,11 @@ Ref<DatabaseConnection> Database::get_connection() {
}
Ref<DatabaseConnection> Database::_allocate_connection() {
//Ref<DatabaseConnection> dbc;
//dbc.instance();
//dbc->set_owner(this); //if needed
//return dbc;
return Ref<DatabaseConnection>();
}

View File

@ -29,10 +29,16 @@ String DatabaseConnection::escape(const String &str) {
void DatabaseConnection::escape_to(const String &str, String *to) {
}
Ref<Database> DatabaseConnection::get_owner() {
return Ref<Database>(_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);
}

View File

@ -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<Database> 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