diff --git a/database/migrations/m0.sql b/database/migrations/m0.sql index b4bcaac..0695568 100644 --- a/database/migrations/m0.sql +++ b/database/migrations/m0.sql @@ -132,5 +132,5 @@ VALUES ('created', UTC_TIMESTAMP()); --creating default currencies INSERT IGNORE INTO -currencies (`code`, `title`, `manual`, `description`, `type`, `value`) -VALUES ('USD', 'United States Dollar', TRUE, 'Base currency', 0, 1); +currencies (`code`, `title`, `manual`, `description`, `type`, `value`, `icon`) +VALUES ('USD', 'United States Dollar', TRUE, 'Base currency', 1, 1, 'currency-usd'); diff --git a/database/mysql/mysql.cpp b/database/mysql/mysql.cpp index ea76b75..be6695f 100644 --- a/database/mysql/mysql.cpp +++ b/database/mysql/mysql.cpp @@ -27,8 +27,8 @@ constexpr const char* insertAsset = "INSERT INTO assets (`owner`, `currency`, `t " VALUES (?, ?, ?, ?, ?, ?, 1)"; constexpr const char* removeAsset = "DELETE FROM assets where `id` = ? AND `owner` = ?"; constexpr const char* selectUsedCurrencies = "SELECT c.id, c.code, c.title, c.manual, c.icon FROM currencies c" - "JOIN assets a ON c.id = a.currency" - "WHERE a.owner = ?"; + " JOIN assets a ON c.id = a.currency" + " WHERE a.owner = ?"; static const std::filesystem::path buildSQLPath = "database"; @@ -379,7 +379,7 @@ bool DB::MySQL::deleteAsset(uint32_t assetId, uint32_t actorId) { } std::vector DB::MySQL::listUsedCurrencies(uint32_t owner) { - Statement list(&connection, removeAsset); + Statement list(&connection, selectUsedCurrencies); list.bind(&owner, MYSQL_TYPE_LONG, true); list.execute(); diff --git a/database/mysql/statement.cpp b/database/mysql/statement.cpp index d770ce4..7b6a93d 100644 --- a/database/mysql/statement.cpp +++ b/database/mysql/statement.cpp @@ -114,13 +114,16 @@ std::vector> DB::MySQL::Statement::fetchResult() { bind[i].buffer_type = field->type; bind[i].buffer_length = field->length; bind[i].length = &lengths[i]; + if (field->flags & UNSIGNED_FLAG) + bind[i].is_unsigned = 1; } if (mysql_stmt_bind_result(raw, bind) != 0) throw std::runtime_error(std::string("Error binding on fetching statement result: ") + mysql_stmt_error(raw)); std::vector> result; - while (mysql_stmt_fetch(raw) == 0) { + int rc; + while ((rc = mysql_stmt_fetch(raw)) == 0) { std::vector& row = result.emplace_back(numColumns); for (unsigned int i = 0; i < numColumns; ++i) { switch (bind[i].buffer_type) { @@ -146,6 +149,10 @@ std::vector> DB::MySQL::Statement::fetchResult() { } } } + if (rc == 1) + throw std::runtime_error(std::string("Error occured fetching data ") + mysql_stmt_error(raw)); + else if (rc == MYSQL_DATA_TRUNCATED) + throw std::runtime_error("Data has been truncated"); return result; } diff --git a/database/schema/asset.cpp b/database/schema/asset.cpp index d1ff7af..6187908 100644 --- a/database/schema/asset.cpp +++ b/database/schema/asset.cpp @@ -38,7 +38,7 @@ nlohmann::json DB::Asset::toJSON () const { result["id"] = id; //result["owner"] = owner; - //result["currency"] = currency; + result["currency"] = currency; result["title"] = title; result["icon"] = icon; result["color"] = color; diff --git a/handler/addasset.cpp b/handler/addasset.cpp index 69e5539..99a7bf3 100644 --- a/handler/addasset.cpp +++ b/handler/addasset.cpp @@ -69,10 +69,10 @@ void Handler::AddAsset::handle (Request& request) { } catch (const DB::NoSession& e) { return error(request, Response::Status::unauthorized); } catch (const std::exception& e) { - std::cerr << "Exception on poll:\n\t" << e.what() << std::endl; + std::cerr << "Exception on " << path << ":\n\t" << e.what() << std::endl; return error(request, Response::Status::internalError); } catch (...) { - std::cerr << "Unknown exception on poll" << std::endl; + std::cerr << "Unknown exception on " << path << std::endl; return error(request, Response::Status::internalError); } } diff --git a/handler/deleteasset.cpp b/handler/deleteasset.cpp index 0d35ba5..9d62463 100644 --- a/handler/deleteasset.cpp +++ b/handler/deleteasset.cpp @@ -50,10 +50,10 @@ void Handler::DeleteAsset::handle (Request& request) { } catch (const DB::NoSession& e) { return error(request, Response::Status::unauthorized); } catch (const std::exception& e) { - std::cerr << "Exception on poll:\n\t" << e.what() << std::endl; + std::cerr << "Exception on " << path << ":\n\t" << e.what() << std::endl; return error(request, Response::Status::internalError); } catch (...) { - std::cerr << "Unknown exception on poll" << std::endl; + std::cerr << "Unknown exception on " << path << std::endl; return error(request, Response::Status::internalError); } } diff --git a/handler/listassets.cpp b/handler/listassets.cpp index de5ace8..21a2825 100644 --- a/handler/listassets.cpp +++ b/handler/listassets.cpp @@ -42,10 +42,10 @@ void Handler::ListAssets::handle (Request& request) { } catch (const DB::NoSession& e) { return error(request, Response::Status::unauthorized); } catch (const std::exception& e) { - std::cerr << "Exception on poll:\n\t" << e.what() << std::endl; + std::cerr << "Exception on " << path << ":\n\t" << e.what() << std::endl; return error(request, Response::Status::internalError); } catch (...) { - std::cerr << "Unknown exception on poll" << std::endl; + std::cerr << "Unknown exception on " << path << std::endl; return error(request, Response::Status::internalError); } } diff --git a/handler/mycurrencies.cpp b/handler/mycurrencies.cpp index eba9e1b..549eef1 100644 --- a/handler/mycurrencies.cpp +++ b/handler/mycurrencies.cpp @@ -42,10 +42,10 @@ void Handler::MyCurrencies::handle (Request& request) { } catch (const DB::NoSession& e) { return error(request, Response::Status::unauthorized); } catch (const std::exception& e) { - std::cerr << "Exception on poll:\n\t" << e.what() << std::endl; + std::cerr << "Exception on " << path << ":\n\t" << e.what() << std::endl; return error(request, Response::Status::internalError); } catch (...) { - std::cerr << "Unknown exception on poll" << std::endl; + std::cerr << "Unknown exception on " << path << std::endl; return error(request, Response::Status::internalError); } } diff --git a/handler/poll.cpp b/handler/poll.cpp index 055e0fd..be92a33 100644 --- a/handler/poll.cpp +++ b/handler/poll.cpp @@ -33,10 +33,10 @@ void Handler::Poll::handle (Request& request) { } catch (const DB::NoSession& e) { return error(request, Result::tokenProblem, Response::Status::unauthorized); } catch (const std::exception& e) { - std::cerr << "Exception on poll:\n\t" << e.what() << std::endl; + std::cerr << "Exception on " << path << ":\n\t" << e.what() << std::endl; return error(request, Result::unknownError, Response::Status::internalError); } catch (...) { - std::cerr << "Unknown exception on poll" << std::endl; + std::cerr << "Unknown exception on " << path << std::endl; return error(request, Result::unknownError, Response::Status::internalError); } }