20 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX;
21 auto exists = std::filesystem::exists(file);
23 check(sqlite3_open_v2(file, &dbc, flags, 0), dbc_);
25 spatial_.reset(spatialite_alloc_connection());
26 spatialite_init_ex(dbc_.get(), spatial_.get(), 0);
29 exec(
"SELECT InitSpatialMetaData(1)");
31 catch (std::exception
const&) {
38 std::stop_callback{tok, [&] { sqlite3_interrupt(dbc_.get()); }};
41 auto first = txt.data();
42 auto last = first + txt.size();
45 while (first != last) {
47 check(sqlite3_prepare_v2(
48 dbc_.get(), first,
int(last - first), &stmt, &first),
53 auto _ = unique_ptr<sqlite3_stmt, sqlite3_finalize>{stmt};
54 int params = sqlite3_bind_parameter_count(stmt);
55 for (
int i{}; i < params && it != ps.end(); ++i, ++it)
56 check(bind_value(stmt, i + 1, *it), dbc_);
57 int cols = sqlite3_column_count(stmt);
58 ret.columns.resize(cols);
59 for (
int i{}; i < cols; ++i)
60 ret.columns[i] = sqlite3_column_name(stmt, i);
61 int ec = sqlite3_step(stmt);
62 for (; SQLITE_DONE != ec; ec = sqlite3_step(stmt)) {
64 auto& row = ret.rows.emplace_back(cols);
65 for (
int i{}; i < cols; ++i)
66 row[i] = column_value(stmt, i);