Commit 125e6ea2 authored by Paul's avatar Paul
Browse files

Format

parent 9b176db8
...@@ -18,7 +18,8 @@ struct sqlite ...@@ -18,7 +18,8 @@ struct sqlite
static sqlite read(const fs::path& p); static sqlite read(const fs::path& p);
static sqlite write(const fs::path& p); static sqlite write(const fs::path& p);
std::vector<std::unordered_map<std::string, std::string>> execute(const std::string& s); std::vector<std::unordered_map<std::string, std::string>> execute(const std::string& s);
private:
private:
std::shared_ptr<sqlite_impl> impl; std::shared_ptr<sqlite_impl> impl;
}; };
......
...@@ -17,12 +17,12 @@ struct sqlite_impl ...@@ -17,12 +17,12 @@ struct sqlite_impl
sqlite3* ptr_tmp = nullptr; sqlite3* ptr_tmp = nullptr;
int rc = sqlite3_open_v2(p.string().c_str(), &ptr_tmp, flags, nullptr); int rc = sqlite3_open_v2(p.string().c_str(), &ptr_tmp, flags, nullptr);
ptr = sqlite3_ptr{ptr_tmp}; ptr = sqlite3_ptr{ptr_tmp};
if (rc != 0) if(rc != 0)
MIGRAPHX_THROW("error opening " + p.string() + ": " + error_message()); MIGRAPHX_THROW("error opening " + p.string() + ": " + error_message());
} }
template<class F> template <class F>
void exec(const char*sql, F f) void exec(const char* sql, F f)
{ {
auto callback = [](void* obj, auto... xs) -> int { auto callback = [](void* obj, auto... xs) -> int {
try try
...@@ -37,7 +37,7 @@ struct sqlite_impl ...@@ -37,7 +37,7 @@ struct sqlite_impl
} }
}; };
int rc = sqlite3_exec(get(), sql, callback, &f, nullptr); int rc = sqlite3_exec(get(), sql, callback, &f, nullptr);
if (rc != 0) if(rc != 0)
MIGRAPHX_THROW(error_message()); MIGRAPHX_THROW(error_message());
} }
...@@ -71,9 +71,12 @@ std::vector<std::unordered_map<std::string, std::string>> sqlite::execute(const ...@@ -71,9 +71,12 @@ std::vector<std::unordered_map<std::string, std::string>> sqlite::execute(const
impl->exec(s.c_str(), [&](int n, char** texts, char** names) { impl->exec(s.c_str(), [&](int n, char** texts, char** names) {
std::unordered_map<std::string, std::string> row; std::unordered_map<std::string, std::string> row;
row.reserve(n); row.reserve(n);
std::transform(names, names+n, texts, std::inserter(row, row.begin()), [&](const char* name, const char* text) { std::transform(
return std::make_pair(name, text); names,
}); names + n,
texts,
std::inserter(row, row.begin()),
[&](const char* name, const char* text) { return std::make_pair(name, text); });
result.push_back(row); result.push_back(row);
}); });
return result; return result;
......
...@@ -14,7 +14,6 @@ const std::string select_all = R"__migraphx__( ...@@ -14,7 +14,6 @@ const std::string select_all = R"__migraphx__(
SELECT * FROM test_db; SELECT * FROM test_db;
)__migraphx__"; )__migraphx__";
TEST_CASE(read_write) TEST_CASE(read_write)
{ {
migraphx::tmp_dir td{}; migraphx::tmp_dir td{};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment