From 04ef468ffa533b39051af790efd1f3988252000a Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 27 Apr 2024 18:54:12 +0200 Subject: [PATCH] QueryBuilder now uses a StringBuilder internally. --- modules/database/query_builder.cpp | 12 ++++++++--- modules/database/query_builder.h | 3 ++- .../database_sqlite/sqlite3_query_builder.cpp | 21 ++++++++++++++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/database/query_builder.cpp b/modules/database/query_builder.cpp index 3ab876a00..d97ef3266 100644 --- a/modules/database/query_builder.cpp +++ b/modules/database/query_builder.cpp @@ -38,7 +38,8 @@ String QueryBuilder::get_result() { return query_result; } void QueryBuilder::set_result(const String &val) { - query_result = val; + query_result.clear(); + query_result.append(val); } QueryBuilder *QueryBuilder::select() { @@ -235,7 +236,12 @@ QueryBuilder *QueryBuilder::order_by(const String &col) { QueryBuilder *QueryBuilder::corder_by() { ERR_FAIL_COND_V(query_result.length() <= 2, this); - query_result[query_result.length() - 2] = ' '; + String qr = query_result.as_string(); + + qr[qr.length() - 2] = ' '; + + query_result.clear(); + query_result.append(qr); return this; } @@ -307,7 +313,7 @@ QueryBuilder *QueryBuilder::end_command() { } QueryBuilder *QueryBuilder::reset() { - query_result = ""; + query_result.clear(); return this; } diff --git a/modules/database/query_builder.h b/modules/database/query_builder.h index f20df998c..016421cb2 100644 --- a/modules/database/query_builder.h +++ b/modules/database/query_builder.h @@ -33,6 +33,7 @@ /*************************************************************************/ #include "core/string/ustring.h" +#include "core/string/string_builder.h" #include "core/object/reference.h" @@ -245,7 +246,7 @@ protected: Ref _reset_bind(); - String query_result; + StringBuilder query_result; }; #endif diff --git a/modules/database_sqlite/sqlite3_query_builder.cpp b/modules/database_sqlite/sqlite3_query_builder.cpp index ef999e3b5..f11fe00d2 100644 --- a/modules/database_sqlite/sqlite3_query_builder.cpp +++ b/modules/database_sqlite/sqlite3_query_builder.cpp @@ -24,7 +24,12 @@ QueryBuilder *SQLite3QueryBuilder::del() { QueryBuilder *SQLite3QueryBuilder::cvalues() { ERR_FAIL_COND_V(query_result.length() <= 2, this); - query_result[query_result.length() - 2] = ' '; + String qr = query_result.as_string(); + + qr[qr.length() - 2] = ' '; + + query_result.clear(); + query_result.append(qr); query_result += ") "; return this; @@ -32,7 +37,12 @@ QueryBuilder *SQLite3QueryBuilder::cvalues() { QueryBuilder *SQLite3QueryBuilder::next_value() { ERR_FAIL_COND_V(query_result.length() <= 2, this); - query_result[query_result.length() - 2] = ' '; + String qr = query_result.as_string(); + + qr[qr.length() - 2] = ' '; + + query_result.clear(); + query_result.append(qr); query_result += "), ("; return this; @@ -215,7 +225,12 @@ QueryBuilder *SQLite3QueryBuilder::sets() { QueryBuilder *SQLite3QueryBuilder::cset() { ERR_FAIL_COND_V(query_result.length() <= 2, this); - query_result[query_result.length() - 2] = ' '; + String qr = query_result.as_string(); + + qr[qr.length() - 2] = ' '; + + query_result.clear(); + query_result.append(qr); return this; }