From 07f571dbc9e459fef32fa8a7b7c7b80bf534d60c Mon Sep 17 00:00:00 2001 From: Andrey Kutin Date: Thu, 15 Oct 2026 21:31:24 +0300 Subject: [PATCH] fix: renaming the field 'value' (of type 'int') to 'text' (of type 'text') in the database --- CMakeLists.txt | 2 +- src/database.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 054020f..8988a83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ install(FILES LICENSE DESTINATION /usr/share/doc/cards) # ─── Packaging (CPack) ──────────────────────────────────────────────── set(CPACK_PACKAGE_NAME "cards") -set(CPACK_PACKAGE_VERSION "1.0.0") +set(CPACK_PACKAGE_VERSION "1.0.1") set(CPACK_PACKAGE_VENDOR "cards") set(CPACK_PACKAGE_MAINTAINER "adwet") set(CPACK_PACKAGE_CONTACT "adwet@yandex.ru") diff --git a/src/database.cpp b/src/database.cpp index fa3880a..a6bf778 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -15,7 +15,7 @@ Database::Database(const DatabaseConfig& cfg, int workers) "CREATE TABLE IF NOT EXISTS random_data (" " id SERIAL PRIMARY KEY," " name VARCHAR(100) NOT NULL," - " value INTEGER NOT NULL," + " text TEXT NOT NULL," " description TEXT," " created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP" ")" @@ -104,14 +104,14 @@ json Database::getRandomRecord(pqxx::connection& conn, std::mt19937& rng) { pqxx::work txn(conn); auto result = txn.exec( - "SELECT id, name, value, description, created_at " + "SELECT id, name, text, description, created_at " "FROM random_data " "WHERE id = $1", pqxx::params{randomId} ); if (result.empty()) { - result = txn.exec("SELECT id, name, value, description, created_at FROM random_data LIMIT 1"); + result = txn.exec("SELECT id, name, text, description, created_at FROM random_data LIMIT 1"); } if (result.empty()) { @@ -126,7 +126,7 @@ json Database::getRandomRecord(pqxx::connection& conn, std::mt19937& rng) { json response = { {"id", row[0].as()}, {"name", row[1].as()}, - {"value", row[2].as()}, + {"text", row[2].as()}, {"description", row[3].as()}, {"created_at", row[4].as()}, {"timestamp", std::chrono::system_clock::now().time_since_epoch().count()} @@ -182,7 +182,7 @@ json Database::getRandomRecordsFast(pqxx::connection& conn, const int count) { "SELECT" " rd.id," " rd.name," - " rd.value," + " rd.text," " rd.description," " rd.created_at" "FROM random_selection AS rs" @@ -203,7 +203,7 @@ json Database::getRandomRecordsFast(pqxx::connection& conn, const int count) { response.push_back({ {"id", row[0].as()}, {"name", row[1].as()}, - {"value", row[2].as()}, + {"text", row[2].as()}, {"description", row[3].as()}, {"created_at", row[4].as()} }); @@ -252,7 +252,7 @@ json Database::getRandomRecordsSlow(pqxx::connection& conn, std::mt19937& rng, c response.push_back({ {"id", row[0].as()}, {"name", row[1].as()}, - {"value", row[2].as()}, + {"text", row[2].as()}, {"description", row[3].as()}, {"created_at", row[4].as()} }); @@ -319,7 +319,7 @@ int Database::getTotalCount(pqxx::connection& conn) { std::string Database::getQueryRandomIds(const int count) { std::string query = - "SELECT id, name, value, description, created_at " + "SELECT id, name, text, description, created_at " "FROM random_data WHERE id IN ("; for (size_t i = 0; i < count; ++i) {