From 66e90498912ba75cafd1174e58b35d2c0ce71a95 Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Thu, 25 Jan 2024 03:46:28 +0000 Subject: [PATCH] Add more logging --- src/gilles/gameloop/hoeldb.c | 79 ++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/src/gilles/gameloop/hoeldb.c b/src/gilles/gameloop/hoeldb.c index acdb01c..2505b09 100644 --- a/src/gilles/gameloop/hoeldb.c +++ b/src/gilles/gameloop/hoeldb.c @@ -371,10 +371,20 @@ int adddriver(struct _h_connection* conn, int driverid, const char* drivername) json_object_set_new(values, "steam64_id", json_integer(17)); json_object_set_new(values, "country", json_string("USA")); json_array_append(json_arr, values); - int res = h_insert(conn, root, NULL); + + char* qq; + int res = h_insert(conn, root, &qq); json_decref(root); json_decref(values); + if (res != 0) + { + sloge("driver insert result %i", res); + sloge("driver insert query %s", qq); + return -1; + } + + driverid = getLastInsertID(conn); return driverid; } @@ -394,9 +404,19 @@ int addevent(struct _h_connection* conn, int track_config) json_object_set_new(values, "event_name", json_string("default")); //event_id | server_name | track_config_id | event_name | team_event | active | livery_preview | use_number | practice_duration | quali_duration | race_duration | race_duration_type | race_wait_time | race_extra_laps | reverse_grid_positions json_array_append(json_arr, values); - int res = h_insert(conn, root, NULL); + + char* qq; + int res = h_insert(conn, root, &qq); json_decref(root); json_decref(values); + + if (res != 0) + { + sloge("event insert result %i", res); + sloge("event insert query %s", qq); + return -1; + } + return getLastInsertID(conn); } @@ -426,10 +446,19 @@ int addstint(struct _h_connection* conn, int sessionid, int driverid, int carid, json_object_set_new(values, "started_at", json_string("NOW()") ); json_array_append(json_arr, values); - int res = h_insert(conn, root, NULL); - slogt("stint insert response: %i", res); + + char* qq; + int res = h_insert(conn, root, &qq); json_decref(root); json_decref(values); + + if (res != 0) + { + sloge("stint insert result %i", res); + sloge("stint insert query %s", qq); + return -1; + } + return getLastInsertID(conn); } @@ -449,11 +478,19 @@ int addstintlap(struct _h_connection* conn, int stintid, SimData* simdata) json_object_set_new(values, "stint_id", json_integer(stintid)); json_object_set_new(values, "tyre", json_string("Vintage") ); - json_array_append(json_arr, values); - int res = h_insert(conn, root, NULL); - slogt("stint lap insert response: %i", res); + + char* qq; + int res = h_insert(conn, root, &qq); json_decref(root); json_decref(values); + + if (res != 0) + { + sloge("stint lap insert result %i", res); + sloge("stint lap insert query %s", qq); + return -1; + } + return getLastInsertID(conn); } @@ -478,12 +515,20 @@ int addcar(struct _h_connection* conn, int carid, const char* carname) json_object_set_new(values, "manufacturer", json_string("Unknown")); json_object_set_new(values, "car_class", json_string("Unknown")); json_array_append(json_arr, values); - int res = h_insert(conn, root, NULL); + + char* qq; + int res = h_insert(conn, root, &qq); json_decref(root); json_decref(values); - carid = getLastInsertID(conn); - return carid; + if (res != 0) + { + sloge("car insert result %i", res); + sloge("car insert query %s", qq); + return -1; + } + + return getLastInsertID(conn); } int addtelemetry(struct _h_connection* conn, int points, int stintid) @@ -499,12 +544,20 @@ int addtelemetry(struct _h_connection* conn, int points, int stintid) json_object_set_new(values, "lap_id", json_integer(stintid)); json_object_set_new(values, "points", json_integer(points)); json_array_append(json_arr, values); - int res = h_insert(conn, root, NULL); + + char* qq; + int res = h_insert(conn, root, &qq); json_decref(root); json_decref(values); - int telemid = getLastInsertID(conn); - return telemid; + if (res != 0) + { + sloge("telemetry insert result %i", res); + sloge("telemetry insert query %s", qq); + return -1; + } + + return getLastInsertID(conn); }