Currencies request debug, sign now is handled in statement results

This commit is contained in:
Blue 2024-03-28 20:20:21 -03:00
parent db37abacd2
commit 07003c2fe6
Signed by: blue
GPG Key ID: 9B203B252A63EE38
9 changed files with 24 additions and 17 deletions

View File

@ -132,5 +132,5 @@ VALUES ('created', UTC_TIMESTAMP());
--creating default currencies --creating default currencies
INSERT IGNORE INTO INSERT IGNORE INTO
currencies (`code`, `title`, `manual`, `description`, `type`, `value`) currencies (`code`, `title`, `manual`, `description`, `type`, `value`, `icon`)
VALUES ('USD', 'United States Dollar', TRUE, 'Base currency', 0, 1); VALUES ('USD', 'United States Dollar', TRUE, 'Base currency', 1, 1, 'currency-usd');

View File

@ -379,7 +379,7 @@ bool DB::MySQL::deleteAsset(uint32_t assetId, uint32_t actorId) {
} }
std::vector<DB::Currency> DB::MySQL::listUsedCurrencies(uint32_t owner) { std::vector<DB::Currency> DB::MySQL::listUsedCurrencies(uint32_t owner) {
Statement list(&connection, removeAsset); Statement list(&connection, selectUsedCurrencies);
list.bind(&owner, MYSQL_TYPE_LONG, true); list.bind(&owner, MYSQL_TYPE_LONG, true);
list.execute(); list.execute();

View File

@ -114,13 +114,16 @@ std::vector<std::vector<std::any>> DB::MySQL::Statement::fetchResult() {
bind[i].buffer_type = field->type; bind[i].buffer_type = field->type;
bind[i].buffer_length = field->length; bind[i].buffer_length = field->length;
bind[i].length = &lengths[i]; bind[i].length = &lengths[i];
if (field->flags & UNSIGNED_FLAG)
bind[i].is_unsigned = 1;
} }
if (mysql_stmt_bind_result(raw, bind) != 0) if (mysql_stmt_bind_result(raw, bind) != 0)
throw std::runtime_error(std::string("Error binding on fetching statement result: ") + mysql_stmt_error(raw)); throw std::runtime_error(std::string("Error binding on fetching statement result: ") + mysql_stmt_error(raw));
std::vector<std::vector<std::any>> result; std::vector<std::vector<std::any>> result;
while (mysql_stmt_fetch(raw) == 0) { int rc;
while ((rc = mysql_stmt_fetch(raw)) == 0) {
std::vector<std::any>& row = result.emplace_back(numColumns); std::vector<std::any>& row = result.emplace_back(numColumns);
for (unsigned int i = 0; i < numColumns; ++i) { for (unsigned int i = 0; i < numColumns; ++i) {
switch (bind[i].buffer_type) { switch (bind[i].buffer_type) {
@ -146,6 +149,10 @@ std::vector<std::vector<std::any>> 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; return result;
} }

View File

@ -38,7 +38,7 @@ nlohmann::json DB::Asset::toJSON () const {
result["id"] = id; result["id"] = id;
//result["owner"] = owner; //result["owner"] = owner;
//result["currency"] = currency; result["currency"] = currency;
result["title"] = title; result["title"] = title;
result["icon"] = icon; result["icon"] = icon;
result["color"] = color; result["color"] = color;

View File

@ -69,10 +69,10 @@ void Handler::AddAsset::handle (Request& request) {
} catch (const DB::NoSession& e) { } catch (const DB::NoSession& e) {
return error(request, Response::Status::unauthorized); return error(request, Response::Status::unauthorized);
} catch (const std::exception& e) { } 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); return error(request, Response::Status::internalError);
} catch (...) { } catch (...) {
std::cerr << "Unknown exception on poll" << std::endl; std::cerr << "Unknown exception on " << path << std::endl;
return error(request, Response::Status::internalError); return error(request, Response::Status::internalError);
} }
} }

View File

@ -50,10 +50,10 @@ void Handler::DeleteAsset::handle (Request& request) {
} catch (const DB::NoSession& e) { } catch (const DB::NoSession& e) {
return error(request, Response::Status::unauthorized); return error(request, Response::Status::unauthorized);
} catch (const std::exception& e) { } 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); return error(request, Response::Status::internalError);
} catch (...) { } catch (...) {
std::cerr << "Unknown exception on poll" << std::endl; std::cerr << "Unknown exception on " << path << std::endl;
return error(request, Response::Status::internalError); return error(request, Response::Status::internalError);
} }
} }

View File

@ -42,10 +42,10 @@ void Handler::ListAssets::handle (Request& request) {
} catch (const DB::NoSession& e) { } catch (const DB::NoSession& e) {
return error(request, Response::Status::unauthorized); return error(request, Response::Status::unauthorized);
} catch (const std::exception& e) { } 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); return error(request, Response::Status::internalError);
} catch (...) { } catch (...) {
std::cerr << "Unknown exception on poll" << std::endl; std::cerr << "Unknown exception on " << path << std::endl;
return error(request, Response::Status::internalError); return error(request, Response::Status::internalError);
} }
} }

View File

@ -42,10 +42,10 @@ void Handler::MyCurrencies::handle (Request& request) {
} catch (const DB::NoSession& e) { } catch (const DB::NoSession& e) {
return error(request, Response::Status::unauthorized); return error(request, Response::Status::unauthorized);
} catch (const std::exception& e) { } 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); return error(request, Response::Status::internalError);
} catch (...) { } catch (...) {
std::cerr << "Unknown exception on poll" << std::endl; std::cerr << "Unknown exception on " << path << std::endl;
return error(request, Response::Status::internalError); return error(request, Response::Status::internalError);
} }
} }

View File

@ -33,10 +33,10 @@ void Handler::Poll::handle (Request& request) {
} catch (const DB::NoSession& e) { } catch (const DB::NoSession& e) {
return error(request, Result::tokenProblem, Response::Status::unauthorized); return error(request, Result::tokenProblem, Response::Status::unauthorized);
} catch (const std::exception& e) { } 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); return error(request, Result::unknownError, Response::Status::internalError);
} catch (...) { } 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); return error(request, Result::unknownError, Response::Status::internalError);
} }
} }