diff --git a/src/common/database.h b/src/common/database.h index 13f7954720b..119e00c7ac6 100644 --- a/src/common/database.h +++ b/src/common/database.h @@ -332,9 +332,21 @@ namespace db // @return A unique pointer to the result set of the query. // @note Everything in database-land is 1-indexed, not 0-indexed. template - auto query(std::string const& query, Args&&... args) + auto query(std::string const& query, Args&&... args) -> std::unique_ptr { - return queryStr(fmt::sprintf(query, std::forward(args)...)); + TracyZoneScoped; + try + { + const auto formattedQuery = fmt::sprintf(query, std::forward(args)...); + return queryStr(formattedQuery); + } + catch (const std::exception& e) + { + ShowError("Query Failed: %s", e.what()); + ShowError("Query Failed: %s", str(query.c_str())); + } + + return nullptr; } // @brief Execute a prepared statement with the given query string and arguments. @@ -528,6 +540,9 @@ namespace db case '\\': // Backslash result += "\\\\"; break; + case '%': // Percent (reserved by sprintf, etc.) + result += "%%"; + break; default: result += ch; break;