Skip to content

Commit 2f4d16d

Browse files
committed
Replace printerr with ERR_PRINT macro
1 parent fa0c534 commit 2f4d16d

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/gdsqlite.cpp

+31-31
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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT(" --> 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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT(" --> SQL error: " + error_message);
352352
return false;
353353
} else if (verbosity_level > VerbosityLevel::NORMAL) {
354354
UtilityFunctions::print(" --> Query succeeded");
@@ -361,7 +361,7 @@ bool SQLite::query_with_bindings(const String &p_query, Array param_bindings) {
361361
}
362362

363363
if (!param_bindings.is_empty()) {
364-
UtilityFunctions::push_warning("GDSQLite Warning: Provided number of bindings exceeded the required number in statement! (" + String(std::to_string(param_bindings.size()).c_str()) + " unused parameter(s))");
364+
WARN_PRINT("GDSQLite Warning: Provided number of bindings exceeded the required number in statement! (" + String(std::to_string(param_bindings.size()).c_str()) + " unused parameter(s))");
365365
}
366366

367367
return true;
@@ -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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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+
ERR_PRINT("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: " + String(std::strerror(errno)) + " (" + import_path + ")");
819+
ERR_PRINT("GDSQLite Error: " + String(std::strerror(errno)) + " (" + import_path + ")");
820820
return false;
821821
}
822822
std::stringstream buffer;
@@ -831,7 +831,7 @@ bool SQLite::import_from_json(String import_path) {
831831
Error error = json->parse(json_string);
832832
if (error != Error::OK) {
833833
/* Throw a parsing error */
834-
UtilityFunctions::printerr("GDSQLite Error: parsing failed! reason: " + json->get_error_message() + ", at line: " + String::num_int64(json->get_error_line()));
834+
ERR_PRINT("GDSQLite Error: parsing failed! reason: " + json->get_error_message() + ", at line: " + String::num_int64(json->get_error_line()));
835835
return false;
836836
}
837837
Array database_array = json->get_data();
@@ -917,7 +917,7 @@ bool SQLite::import_from_json(String import_path) {
917917
int64_t number_of_rows = object.row_array.size();
918918
for (int64_t i = 0; i <= number_of_rows - 1; i++) {
919919
if (object.row_array[i].get_type() != Variant::DICTIONARY) {
920-
UtilityFunctions::printerr("GDSQLite Error: All elements of the Array should be of type Dictionary");
920+
ERR_PRINT("GDSQLite Error: All elements of the Array should be of type Dictionary");
921921
return false;
922922
}
923923
if (!insert_row(object.name, object.row_array[i])) {
@@ -1002,7 +1002,7 @@ bool SQLite::export_to_json(String export_path) {
10021002

10031003
std::ofstream ofs(char_path, std::ios::trunc);
10041004
if (ofs.fail()) {
1005-
UtilityFunctions::printerr("GDSQLite Error: " + String(std::strerror(errno)) + " (" + export_path + ")");
1005+
ERR_PRINT("GDSQLite Error: " + String(std::strerror(errno)) + " (" + export_path + ")");
10061006
return false;
10071007
}
10081008
Ref<JSON> json;
@@ -1027,22 +1027,22 @@ bool SQLite::validate_json(const Array &database_array, std::vector<object_struc
10271027
/* Get the name of the object */
10281028
if (!temp_dict.has("name")) {
10291029
/* Did not find the necessary key! */
1030-
UtilityFunctions::printerr("GDSQlite Error: Did not find required key \"name\" in the supplied json-file");
1030+
ERR_PRINT("GDSQlite Error: Did not find required key \"name\" in the supplied json-file");
10311031
return false;
10321032
}
10331033
new_object.name = temp_dict["name"];
10341034

10351035
/* Extract the sql template for generating the object */
10361036
if (!temp_dict.has("sql")) {
10371037
/* Did not find the necessary key! */
1038-
UtilityFunctions::printerr("GDSQlite Error: Did not find required key \"sql\" in the supplied json-file");
1038+
ERR_PRINT("GDSQlite Error: Did not find required key \"sql\" in the supplied json-file");
10391039
return false;
10401040
}
10411041
new_object.sql = temp_dict["sql"];
10421042

10431043
if (!temp_dict.has("type")) {
10441044
/* Did not find the necessary key! */
1045-
UtilityFunctions::printerr("GDSQlite Error: Did not find required key \"type\" in the supplied json-file");
1045+
ERR_PRINT("GDSQlite Error: Did not find required key \"type\" in the supplied json-file");
10461046
return false;
10471047
}
10481048
if (temp_dict["type"] == String("table")) {
@@ -1053,10 +1053,10 @@ bool SQLite::validate_json(const Array &database_array, std::vector<object_struc
10531053

10541054
if (!temp_dict.has("row_array")) {
10551055
/* Did not find the necessary key! */
1056-
UtilityFunctions::printerr("GDSQlite Error: Did not find required key \"row_array\" in the supplied json-file");
1056+
ERR_PRINT("GDSQlite Error: Did not find required key \"row_array\" in the supplied json-file");
10571057
return false;
10581058
} else if (Variant(temp_dict["row_array"]).get_type() != Variant::ARRAY) {
1059-
UtilityFunctions::printerr("GDSQlite Error: The value of the key \"row_array\" should consist of an array of rows");
1059+
ERR_PRINT("GDSQlite Error: The value of the key \"row_array\" should consist of an array of rows");
10601060
return false;
10611061
}
10621062
new_object.row_array = temp_dict["row_array"];
@@ -1068,7 +1068,7 @@ bool SQLite::validate_json(const Array &database_array, std::vector<object_struc
10681068
new_object.type = TRIGGER;
10691069
} else {
10701070
/* Did not find the necessary key! */
1071-
UtilityFunctions::printerr("GDSQlite Error: The value of key \"type\" is restricted to \"table\", \"index\", \"view\" or \"trigger\"");
1071+
ERR_PRINT("GDSQlite Error: The value of key \"type\" is restricted to \"table\", \"index\", \"view\" or \"trigger\"");
10721072
return false;
10731073
}
10741074

@@ -1213,7 +1213,7 @@ int SQLite::enable_load_extension(const bool &p_onoff) {
12131213
rc = sqlite3_enable_load_extension(db, 0);
12141214
}
12151215
if (rc != SQLITE_OK) {
1216-
UtilityFunctions::printerr("GDSQLite Error: Extension loading cannot be enabled/disabled.");
1216+
ERR_PRINT("GDSQLite Error: Extension loading cannot be enabled/disabled.");
12171217
}
12181218
return rc;
12191219
}
@@ -1237,7 +1237,7 @@ int SQLite::load_extension(const String &p_path, const String &entrypoint) {
12371237
sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 0, NULL);
12381238

12391239
if (rc != SQLITE_OK) {
1240-
UtilityFunctions::printerr("GDSQLite Error: Unable to load extension: " + String::utf8(zErrMsg));
1240+
ERR_PRINT("GDSQLite Error: Unable to load extension: " + String::utf8(zErrMsg));
12411241
sqlite3_free(zErrMsg);
12421242
return rc;
12431243
}

0 commit comments

Comments
 (0)