Use String length() instead of size() in QueryBuilder, also guard against overindexing.

This commit is contained in:
Relintai 2022-12-20 23:54:50 +01:00
parent 3d63a84be9
commit cb409757c3
2 changed files with 10 additions and 2 deletions

View File

@ -201,7 +201,9 @@ QueryBuilder *QueryBuilder::order_by(const String &col) {
} }
QueryBuilder *QueryBuilder::corder_by() { QueryBuilder *QueryBuilder::corder_by() {
query_result[query_result.size() - 2] = ' '; ERR_FAIL_COND_V(query_result.length() <= 2, this);
query_result[query_result.length() - 2] = ' ';
return this; return this;
} }
@ -212,7 +214,7 @@ QueryBuilder *QueryBuilder::order_by_add_col(const String &col) {
} }
QueryBuilder *QueryBuilder::asc(const String &col) { QueryBuilder *QueryBuilder::asc(const String &col) {
if (col == "") { if (col == "") {
query_result += "ASC,"; query_result += "ASC, ";
} else { } else {
query_result += col + " ASC, "; query_result += col + " ASC, ";
} }

View File

@ -21,12 +21,16 @@ QueryBuilder *SQLite3QueryBuilder::del() {
} }
QueryBuilder *SQLite3QueryBuilder::cvalues() { QueryBuilder *SQLite3QueryBuilder::cvalues() {
ERR_FAIL_COND_V(query_result.length() <= 2, this);
query_result[query_result.length() - 2] = ' '; query_result[query_result.length() - 2] = ' ';
query_result += ") "; query_result += ") ";
return this; return this;
} }
QueryBuilder *SQLite3QueryBuilder::next_value() { QueryBuilder *SQLite3QueryBuilder::next_value() {
ERR_FAIL_COND_V(query_result.length() <= 2, this);
query_result[query_result.length() - 2] = ' '; query_result[query_result.length() - 2] = ' ';
query_result += "), ("; query_result += "), (";
@ -208,6 +212,8 @@ QueryBuilder *SQLite3QueryBuilder::sets() {
return this; return this;
} }
QueryBuilder *SQLite3QueryBuilder::cset() { QueryBuilder *SQLite3QueryBuilder::cset() {
ERR_FAIL_COND_V(query_result.length() <= 2, this);
query_result[query_result.length() - 2] = ' '; query_result[query_result.length() - 2] = ' ';
return this; return this;