1#ifndef NGEN_GEOPACKAGE_SQLITE_H
2#define NGEN_GEOPACKAGE_SQLITE_H
9#include <boost/core/span.hpp>
17 using std::runtime_error::runtime_error;
19 sqlite_error(
const std::string& origin_func,
int code,
const std::string& extra =
"");
34 sqlite3_finalize(stmt);
38 using sqlite_t = std::unique_ptr<sqlite3, deleter>;
39 using stmt_t = std::unique_ptr<sqlite3_stmt, deleter>;
51 bool done() const noexcept;
79 int find(const std::
string& name) const noexcept;
83 const boost::span<const std::
string>
columns() const noexcept;
90 const boost::span<const
int>
types() const noexcept;
99 Tp
get(
int col) const;
106 template<typename Tp>
107 Tp
get(const std::
string& col)
const
112 sqlite3_stmt*
ptr_() const noexcept;
138 explicit
database(const std::
string& path);
149 bool contains(const std::
string& table);
155 iterator query(const std::
string& statement, const boost::span<const std::
string> binds = {});
170 std::array<std::string,
sizeof...(params)> binds = { params... };
171 return query(statement, binds);
Definition ngen_sqlite.hpp:23
iterator query(const std::string &statement, const boost::span< const std::string > binds={})
Query the SQLite Database and get the result.
Definition ngen_sqlite.cpp:205
bool contains(const std::string &table)
Check if SQLite database contains a given table.
Definition ngen_sqlite.cpp:198
sqlite3 * connection() const noexcept
Return the originating sqlite3 database pointer.
Definition ngen_sqlite.cpp:193
std::unique_ptr< sqlite3_stmt, deleter > stmt_t
Definition ngen_sqlite.hpp:39
std::unique_ptr< sqlite3, deleter > sqlite_t
Definition ngen_sqlite.hpp:38
iterator query(const std::string &statement, const Ts &... params)
Query the SQLite Database with a bound statement and get the result.
Definition ngen_sqlite.hpp:168
sqlite_t conn_
Definition ngen_sqlite.hpp:175
conjunction< std::is_convertible< From, To >::value... > all_is_convertible
Checks that all types {From} are convertible to {T}.
Definition traits.hpp:41
Definition DomainLayer.hpp:9
Deleter used to provide smart pointer support for sqlite3 structs.
Definition ngen_sqlite.hpp:26
void operator()(sqlite3_stmt *stmt)
Definition ngen_sqlite.hpp:32
void operator()(sqlite3 *db)
Definition ngen_sqlite.hpp:27
Definition ngen_sqlite.hpp:43
const boost::span< const int > types() const noexcept
Get a span of column types.
Definition ngen_sqlite.cpp:120
int ncol_
Definition ngen_sqlite.hpp:119
int find(const std::string &name) const noexcept
Return the column index for a named column.
Definition ngen_sqlite.cpp:107
stmt_t stmt_
Definition ngen_sqlite.hpp:115
const boost::span< const std::string > columns() const noexcept
Get a span of column names.
Definition ngen_sqlite.cpp:114
bool done() const noexcept
Check if a row iterator is finished.
Definition ngen_sqlite.cpp:51
int num_columns() const noexcept
Get the number of columns within this iterator.
Definition ngen_sqlite.cpp:102
sqlite3_stmt * ptr_() const noexcept
Definition ngen_sqlite.cpp:46
int current_row() const noexcept
Get the current row index for the iterator.
Definition ngen_sqlite.cpp:97
iterator & next()
Step into the next row of a SQLite query.
Definition ngen_sqlite.cpp:56
std::vector< int > types_
Definition ngen_sqlite.hpp:122
Tp get(int col) const
Get a column value from a row iterator by index.
std::vector< std::string > names_
Definition ngen_sqlite.hpp:121
int done_
Definition ngen_sqlite.hpp:118
void handle_get_index_(int col) const
Definition ngen_sqlite.cpp:126
iterator & restart()
Restart an iteration to its initial state.
Definition ngen_sqlite.cpp:89
int step_
Definition ngen_sqlite.hpp:117
Definition ngen_sqlite.hpp:16
sqlite_error(const std::string &origin_func, int code, const std::string &extra="")
error codes: https://www.sqlite.org/rescode.html
Definition ngen_sqlite.cpp:12