Currencies request debug, sign now is handled in statement results
This commit is contained in:
parent
db37abacd2
commit
07003c2fe6
@ -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');
|
||||
|
@ -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::Currency> DB::MySQL::listUsedCurrencies(uint32_t owner) {
|
||||
Statement list(&connection, removeAsset);
|
||||
Statement list(&connection, selectUsedCurrencies);
|
||||
list.bind(&owner, MYSQL_TYPE_LONG, true);
|
||||
list.execute();
|
||||
|
||||
|
@ -114,13 +114,16 @@ std::vector<std::vector<std::any>> 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<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);
|
||||
for (unsigned int i = 0; i < numColumns; ++i) {
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user