内存优化
This commit is contained in:
@@ -205,38 +205,30 @@ External_Resource_Status External_Resources::clear_table(SQLite::Database& db, c
|
||||
}
|
||||
|
||||
std::optional<External_Database_Row>
|
||||
External_Resources::query_one(SQLite::Database& db, const std::vector<std::string>& primary_key_values) const
|
||||
{
|
||||
External_Resources::query_one(SQLite::Database& db, const std::vector<std::string>& primary_key_values) const {
|
||||
const auto& columns = primary_key_columns();
|
||||
if (columns.size() != primary_key_values.size())
|
||||
{
|
||||
if (columns.size() != primary_key_values.size()) {
|
||||
throw std::invalid_argument("primary key value count mismatch for resource: " + name);
|
||||
}
|
||||
std::string sql = "SELECT * FROM " + External_Database_Utils::quote_identifier(name) + " WHERE ";
|
||||
for (std::size_t index = 0; index < columns.size(); ++index)
|
||||
{
|
||||
for (std::size_t index = 0; index < columns.size(); ++index) {
|
||||
if (index != 0)
|
||||
sql += " AND ";
|
||||
sql += External_Database_Utils::quote_identifier(columns[index]) + " = ? COLLATE NOCASE";
|
||||
sql += External_Database_Utils::quote_identifier(columns[index]) + " = ?";
|
||||
}
|
||||
sql += " LIMIT 1";
|
||||
SQLite::Statement statement(db, sql);
|
||||
for (std::size_t index = 0; index < primary_key_values.size(); ++index)
|
||||
{
|
||||
for (std::size_t index = 0; index < primary_key_values.size(); ++index) {
|
||||
statement.bind(static_cast<int>(index + 1), External_Database_Utils::normalize_key(primary_key_values[index]));
|
||||
}
|
||||
if (!statement.executeStep())
|
||||
return std::nullopt;
|
||||
External_Database_Row row;
|
||||
for (int index = 0; index < statement.getColumnCount(); ++index)
|
||||
{
|
||||
for (int index = 0; index < statement.getColumnCount(); ++index) {
|
||||
const auto name = statement.getColumnName(index);
|
||||
if (statement.isColumnNull(index))
|
||||
{
|
||||
if (statement.isColumnNull(index)) {
|
||||
row.columns.emplace(name, std::nullopt);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row.columns.emplace(name, statement.getColumn(index).getString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user