From c11cfebdb112e495d530e7753fc945fe8d5a06e4 Mon Sep 17 00:00:00 2001 From: Gent Semaj Date: Sat, 3 Feb 2024 03:13:24 -0500 Subject: [PATCH] Fix account and player counts on startup --- src/db/init.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/db/init.cpp b/src/db/init.cpp index 942522f..b6561be 100644 --- a/src/db/init.cpp +++ b/src/db/init.cpp @@ -226,10 +226,11 @@ static void createTables() { static int getTableSize(std::string tableName) { std::lock_guard lock(dbCrit); // XXX - const char* sql = "SELECT COUNT(*) FROM ?"; + // you aren't allowed to bind the table name + const char* sql = "SELECT COUNT(*) FROM "; + tableName.insert(0, sql); sqlite3_stmt* stmt; - sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); - sqlite3_bind_text(stmt, 1, tableName.c_str(), -1, NULL); + sqlite3_prepare_v2(db, tableName.c_str(), -1, &stmt, NULL); sqlite3_step(stmt); int result = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); @@ -271,12 +272,12 @@ void Database::open() { int players = getTableSize("Players"); std::string message = ""; if (accounts > 0) { - message += ": Found " + std::to_string(accounts) + " Account"; + message += ": Found " + std::to_string(accounts) + " account(s)"; if (accounts > 1) message += "s"; } if (players > 0) { - message += " and " + std::to_string(players) + " Player Character"; + message += " and " + std::to_string(players) + " player(s)"; if (players > 1) message += "s"; }