Skip to content

Commit 3092388

Browse files
committed
Replace printerr with push_error
1 parent 9135be6 commit 3092388

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/gdsqlite.cpp

+30-30
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ SQLite::~SQLite() {
127127

128128
bool SQLite::open_db() {
129129
if (db) {
130-
UtilityFunctions::printerr("GDSQLite Error: Can't open database if connection is already open!");
130+
UtilityFunctions::push_error("GDSQLite Error: Can't open database if connection is already open!");
131131
return false;
132132
}
133133

@@ -157,7 +157,7 @@ bool SQLite::open_db() {
157157
sqlite3_vfs_register(gdsqlite_vfs(), 0);
158158
rc = sqlite3_open_v2(char_path, &db, SQLITE_OPEN_READONLY, "godot");
159159
} else {
160-
UtilityFunctions::printerr("GDSQLite Error: Opening in-memory databases in read-only mode is currently not supported!");
160+
UtilityFunctions::push_error("GDSQLite Error: Opening in-memory databases in read-only mode is currently not supported!");
161161
return false;
162162
}
163163
} else {
@@ -168,7 +168,7 @@ bool SQLite::open_db() {
168168
}
169169

170170
if (rc != SQLITE_OK) {
171-
UtilityFunctions::printerr("GDSQLite Error: Can't open database: " + String::utf8(sqlite3_errmsg(db)));
171+
UtilityFunctions::push_error("GDSQLite Error: Can't open database: " + String::utf8(sqlite3_errmsg(db)));
172172
return false;
173173
} else if (verbosity_level > VerbosityLevel::QUIET) {
174174
UtilityFunctions::print("Opened database successfully (" + path + ")");
@@ -178,7 +178,7 @@ bool SQLite::open_db() {
178178
if (foreign_keys) {
179179
rc = sqlite3_exec(db, "PRAGMA foreign_keys=on;", NULL, NULL, &zErrMsg);
180180
if (rc != SQLITE_OK) {
181-
UtilityFunctions::printerr("GDSQLite Error: Can't enable foreign keys: " + String::utf8(zErrMsg));
181+
UtilityFunctions::push_error("GDSQLite Error: Can't enable foreign keys: " + String::utf8(zErrMsg));
182182
sqlite3_free(zErrMsg);
183183
return false;
184184
}
@@ -191,7 +191,7 @@ bool SQLite::close_db() {
191191
if (db) {
192192
// Cannot close database!
193193
if (sqlite3_close_v2(db) != SQLITE_OK) {
194-
UtilityFunctions::printerr("GDSQLite Error: Can't close database!");
194+
UtilityFunctions::push_error("GDSQLite Error: Can't close database!");
195195
return false;
196196
} else {
197197
db = nullptr;
@@ -202,7 +202,7 @@ bool SQLite::close_db() {
202202
}
203203
}
204204

205-
UtilityFunctions::printerr("GDSQLite Error: Can't close database if connection is not open!");
205+
UtilityFunctions::push_error("GDSQLite Error: Can't close database if connection is not open!");
206206
return false;
207207
}
208208

@@ -231,15 +231,15 @@ bool SQLite::query_with_bindings(const String &p_query, Array param_bindings) {
231231
zErrMsg = sqlite3_errmsg(db);
232232
error_message = String::utf8(zErrMsg);
233233
if (rc != SQLITE_OK) {
234-
UtilityFunctions::printerr(" --> SQL error: " + error_message);
234+
UtilityFunctions::push_error(" --> SQL error: " + error_message);
235235
sqlite3_finalize(stmt);
236236
return false;
237237
}
238238

239239
/* Check if the param_bindings size exceeds the required parameter count */
240240
int parameter_count = sqlite3_bind_parameter_count(stmt);
241241
if (param_bindings.size() < parameter_count) {
242-
UtilityFunctions::printerr("GDSQLite Error: Insufficient number of parameters to satisfy required number of bindings in statement!");
242+
UtilityFunctions::push_error("GDSQLite Error: Insufficient number of parameters to satisfy required number of bindings in statement!");
243243
sqlite3_finalize(stmt);
244244
return false;
245245
}
@@ -284,7 +284,7 @@ bool SQLite::query_with_bindings(const String &p_query, Array param_bindings) {
284284
}
285285

286286
default:
287-
UtilityFunctions::printerr("GDSQLite Error: Binding a parameter of type " + String(std::to_string(binding_value.get_type()).c_str()) + " (TYPE_*) is not supported!");
287+
UtilityFunctions::push_error("GDSQLite Error: Binding a parameter of type " + String(std::to_string(binding_value.get_type()).c_str()) + " (TYPE_*) is not supported!");
288288
sqlite3_finalize(stmt);
289289
return false;
290290
}
@@ -348,7 +348,7 @@ bool SQLite::query_with_bindings(const String &p_query, Array param_bindings) {
348348
zErrMsg = sqlite3_errmsg(db);
349349
error_message = String::utf8(zErrMsg);
350350
if (rc != SQLITE_OK) {
351-
UtilityFunctions::printerr(" --> SQL error: " + error_message);
351+
UtilityFunctions::push_error(" --> SQL error: " + error_message);
352352
return false;
353353
} else if (verbosity_level > VerbosityLevel::NORMAL) {
354354
UtilityFunctions::print(" --> Query succeeded");
@@ -471,18 +471,18 @@ bool SQLite::validate_table_dict(const Dictionary &p_table_dict) {
471471
int64_t number_of_columns = columns.size();
472472
for (int64_t i = 0; i <= number_of_columns - 1; i++) {
473473
if (p_table_dict[columns[i]].get_type() != Variant::DICTIONARY) {
474-
UtilityFunctions::printerr("GDSQLite Error: All values of the table dictionary should be of type Dictionary");
474+
UtilityFunctions::push_error("GDSQLite Error: All values of the table dictionary should be of type Dictionary");
475475
return false;
476476
}
477477

478478
column_dict = p_table_dict[columns[i]];
479479
if (!column_dict.has("data_type")) {
480-
UtilityFunctions::printerr("GDSQLite Error: The field \"data_type\" is a required part of the table dictionary");
480+
UtilityFunctions::push_error("GDSQLite Error: The field \"data_type\" is a required part of the table dictionary");
481481
return false;
482482
}
483483

484484
if (column_dict["data_type"].get_type() != Variant::STRING) {
485-
UtilityFunctions::printerr("GDSQLite Error: The field \"data_type\" should be of type String");
485+
UtilityFunctions::push_error("GDSQLite Error: The field \"data_type\" should be of type String");
486486
return false;
487487
}
488488

@@ -504,7 +504,7 @@ bool SQLite::validate_table_dict(const Dictionary &p_table_dict) {
504504
}
505505

506506
if (data_type_type != default_type) {
507-
UtilityFunctions::printerr("GDSQLite Error: The type of the field \"default\" ( " + String(std::to_string(default_type).c_str()) + " ) should be the same type as the \"datatype\"-field ( " + String(std::to_string(data_type_type).c_str()) + " )");
507+
UtilityFunctions::push_error("GDSQLite Error: The type of the field \"default\" ( " + String(std::to_string(default_type).c_str()) + " ) should be the same type as the \"datatype\"-field ( " + String(std::to_string(data_type_type).c_str()) + " )");
508508
return false;
509509
}
510510
}
@@ -588,7 +588,7 @@ bool SQLite::insert_rows(const String &p_name, const Array &p_row_array) {
588588
int64_t number_of_rows = p_row_array.size();
589589
for (int64_t i = 0; i <= number_of_rows - 1; i++) {
590590
if (p_row_array[i].get_type() != Variant::DICTIONARY) {
591-
UtilityFunctions::printerr("GDSQLite Error: All elements of the Array should be of type Dictionary");
591+
UtilityFunctions::push_error("GDSQLite Error: All elements of the Array should be of type Dictionary");
592592
/* Don't forget to close the transaction! */
593593
/* Maybe we should do a rollback instead? */
594594
query("END TRANSACTION;");
@@ -615,7 +615,7 @@ Array SQLite::select_rows(const String &p_name, const String &p_conditions, cons
615615
int64_t number_of_columns = p_columns_array.size();
616616
for (int64_t i = 0; i <= number_of_columns - 1; i++) {
617617
if (p_columns_array[i].get_type() != Variant::STRING) {
618-
UtilityFunctions::printerr("GDSQLite Error: All elements of the Array should be of type String");
618+
UtilityFunctions::push_error("GDSQLite Error: All elements of the Array should be of type String");
619619
return query_result;
620620
}
621621
query_string += (const String &)p_columns_array[i];
@@ -692,7 +692,7 @@ static void function_callback(sqlite3_context *context, int argc, sqlite3_value
692692

693693
/* Check if the callable is valid */
694694
if (!callable.is_valid()) {
695-
UtilityFunctions::printerr("GDSQLite Error: Supplied function reference is invalid! Aborting callback...");
695+
UtilityFunctions::push_error("GDSQLite Error: Supplied function reference is invalid! Aborting callback...");
696696
return;
697697
}
698698

@@ -793,7 +793,7 @@ bool SQLite::create_function(const String &p_name, const Callable &p_callable, i
793793
/* Create the actual function */
794794
rc = sqlite3_create_function(db, zFunctionName, nArg, eTextRep, pApp, xFunc, xStep, xFinal);
795795
if (rc) {
796-
UtilityFunctions::printerr("GDSQLite Error: " + String(sqlite3_errmsg(db)));
796+
UtilityFunctions::push_error("GDSQLite Error: " + String(sqlite3_errmsg(db)));
797797
return false;
798798
} else if (verbosity_level > VerbosityLevel::NORMAL) {
799799
UtilityFunctions::print("Succesfully added function \"" + p_name + "\" to function registry");
@@ -816,7 +816,7 @@ bool SQLite::import_from_json(String import_path) {
816816
/* Open the json-file and stream its content into a stringstream */
817817
std::ifstream ifs(char_path);
818818
if (ifs.fail()) {
819-
UtilityFunctions::printerr("GDSQLite Error: Failed to open specified json-file (" + import_path + ")");
819+
UtilityFunctions::push_error("GDSQLite Error: Failed to open specified json-file (" + import_path + ")");
820820
return false;
821821
}
822822
std::stringstream buffer;
@@ -832,7 +832,7 @@ bool SQLite::import_from_json(String import_path) {
832832
if (error != Error::OK) {
833833
/* Throw a parsing error */
834834
// TODO: Figure out how to cast a int32_t to a Godot String using the new API
835-
UtilityFunctions::printerr("GDSQLite Error: parsing failed! reason: " + json->get_error_message() + ", at line: ???");
835+
UtilityFunctions::push_error("GDSQLite Error: parsing failed! reason: " + json->get_error_message() + ", at line: ???");
836836
//GODOT_LOG(2, "GDSQLite Error: parsing failed! reason: " + result->get_error_string() + ", at line: " + String::num_int64(result->get_error_line()))
837837
return false;
838838
}
@@ -906,7 +906,7 @@ bool SQLite::import_from_json(String import_path) {
906906
int64_t number_of_rows = object.row_array.size();
907907
for (int64_t i = 0; i <= number_of_rows - 1; i++) {
908908
if (object.row_array[i].get_type() != Variant::DICTIONARY) {
909-
UtilityFunctions::printerr("GDSQLite Error: All elements of the Array should be of type Dictionary");
909+
UtilityFunctions::push_error("GDSQLite Error: All elements of the Array should be of type Dictionary");
910910
return false;
911911
}
912912
if (!insert_row(object.name, object.row_array[i])) {
@@ -991,7 +991,7 @@ bool SQLite::export_to_json(String export_path) {
991991

992992
std::ofstream ofs(char_path, std::ios::trunc);
993993
if (ofs.fail()) {
994-
UtilityFunctions::printerr("GDSQLite Error: Can't open specified json-file, file does not exist or is locked");
994+
UtilityFunctions::push_error("GDSQLite Error: Can't open specified json-file, file does not exist or is locked");
995995
return false;
996996
}
997997
Ref<JSON> json;
@@ -1016,22 +1016,22 @@ bool SQLite::validate_json(const Array &database_array, std::vector<object_struc
10161016
/* Get the name of the object */
10171017
if (!temp_dict.has("name")) {
10181018
/* Did not find the necessary key! */
1019-
UtilityFunctions::printerr("GDSQlite Error: Did not find required key \"name\" in the supplied json-file");
1019+
UtilityFunctions::push_error("GDSQlite Error: Did not find required key \"name\" in the supplied json-file");
10201020
return false;
10211021
}
10221022
new_object.name = temp_dict["name"];
10231023

10241024
/* Extract the sql template for generating the object */
10251025
if (!temp_dict.has("sql")) {
10261026
/* Did not find the necessary key! */
1027-
UtilityFunctions::printerr("GDSQlite Error: Did not find required key \"sql\" in the supplied json-file");
1027+
UtilityFunctions::push_error("GDSQlite Error: Did not find required key \"sql\" in the supplied json-file");
10281028
return false;
10291029
}
10301030
new_object.sql = temp_dict["sql"];
10311031

10321032
if (!temp_dict.has("type")) {
10331033
/* Did not find the necessary key! */
1034-
UtilityFunctions::printerr("GDSQlite Error: Did not find required key \"type\" in the supplied json-file");
1034+
UtilityFunctions::push_error("GDSQlite Error: Did not find required key \"type\" in the supplied json-file");
10351035
return false;
10361036
}
10371037
if (temp_dict["type"] == String("table")) {
@@ -1042,18 +1042,18 @@ bool SQLite::validate_json(const Array &database_array, std::vector<object_struc
10421042

10431043
if (!temp_dict.has("row_array")) {
10441044
/* Did not find the necessary key! */
1045-
UtilityFunctions::printerr("GDSQlite Error: Did not find required key \"row_array\" in the supplied json-file");
1045+
UtilityFunctions::push_error("GDSQlite Error: Did not find required key \"row_array\" in the supplied json-file");
10461046
return false;
10471047
} else if (Variant(temp_dict["row_array"]).get_type() != Variant::ARRAY) {
1048-
UtilityFunctions::printerr("GDSQlite Error: The value of the key \"row_array\" should consist of an array of rows");
1048+
UtilityFunctions::push_error("GDSQlite Error: The value of the key \"row_array\" should consist of an array of rows");
10491049
return false;
10501050
}
10511051
new_object.row_array = temp_dict["row_array"];
10521052
} else if (temp_dict["type"] == String("trigger")) {
10531053
new_object.type = TRIGGER;
10541054
} else {
10551055
/* Did not find the necessary key! */
1056-
UtilityFunctions::printerr(2, "GDSQlite Error: The value of key \"type\" is restricted to either \"table\" or \"trigger\"");
1056+
UtilityFunctions::push_error(2, "GDSQlite Error: The value of key \"type\" is restricted to either \"table\" or \"trigger\"");
10571057
return false;
10581058
}
10591059

@@ -1198,7 +1198,7 @@ int SQLite::enable_load_extension(const bool &p_onoff) {
11981198
rc = sqlite3_enable_load_extension(db, 0);
11991199
}
12001200
if (rc != SQLITE_OK) {
1201-
UtilityFunctions::printerr("GDSQLite Error: Extension loading cannot be enabled/disabled.");
1201+
UtilityFunctions::push_error("GDSQLite Error: Extension loading cannot be enabled/disabled.");
12021202
}
12031203
return rc;
12041204
}
@@ -1222,7 +1222,7 @@ int SQLite::load_extension(const String &p_path, const String &entrypoint) {
12221222
sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 0, NULL);
12231223

12241224
if (rc != SQLITE_OK) {
1225-
UtilityFunctions::printerr("GDSQLite Error: Unable to load extension: " + String::utf8(zErrMsg));
1225+
UtilityFunctions::push_error("GDSQLite Error: Unable to load extension: " + String::utf8(zErrMsg));
12261226
sqlite3_free(zErrMsg);
12271227
return rc;
12281228
}

0 commit comments

Comments
 (0)