NGen
Loading...
Searching...
No Matches
ngen::sqlite::database::iterator Struct Reference

#include <ngen_sqlite.hpp>

+ Collaboration diagram for ngen::sqlite::database::iterator:

Public Member Functions

 iterator ()=delete
 
 iterator (stmt_t &&stmt)
 
bool done () const noexcept
 Check if a row iterator is finished.
 
iteratornext ()
 Step into the next row of a SQLite query.
 
iteratorrestart ()
 Restart an iteration to its initial state.
 
int current_row () const noexcept
 Get the current row index for the iterator.
 
int num_columns () const noexcept
 Get the number of columns within this iterator.
 
int find (const std::string &name) const noexcept
 Return the column index for a named column.
 
const boost::span< const std::string > columns () const noexcept
 Get a span of column names.
 
const boost::span< const int > types () const noexcept
 Get a span of column types.
 
template<typename Tp >
Tp get (int col) const
 Get a column value from a row iterator by index.
 
template<typename Tp >
Tp get (const std::string &col) const
 Get a column value from a row iterator by name.
 
template<>
auto get (int col) const -> double
 

Private Member Functions

sqlite3_stmt * ptr_ () const noexcept
 
void handle_get_index_ (int col) const
 

Private Attributes

stmt_t stmt_
 
int step_ = -1
 
int done_ = false
 
int ncol_ = 0
 
std::vector< std::string > names_
 
std::vector< int > types_
 

Constructor & Destructor Documentation

◆ iterator() [1/2]

ngen::sqlite::database::iterator::iterator ( )
delete

◆ iterator() [2/2]

ngen::sqlite::database::iterator::iterator ( stmt_t && stmt)
explicit

References names_, ncol_, next(), ptr_(), restart(), and types_.

Member Function Documentation

◆ columns()

auto ngen::sqlite::database::iterator::columns ( ) const
noexcept

Get a span of column names.

Returns
column names as a span of strings

Referenced by ngen::geopackage::build_properties().

◆ current_row()

auto ngen::sqlite::database::iterator::current_row ( ) const
noexcept

Get the current row index for the iterator.

Returns
int the current row index, or -1 if next() hasn't been called

◆ done()

auto ngen::sqlite::database::iterator::done ( ) const
noexcept

Check if a row iterator is finished.

Returns
true if next() returned SQLITE_DONE
false if there is more rows available

◆ find()

auto ngen::sqlite::database::iterator::find ( const std::string & name) const
noexcept

Return the column index for a named column.

Parameters
namecolumn name to search for
Returns
int index of given column name, or -1 if not found.

Referenced by get().

◆ get() [1/3]

template<typename Tp >
Tp ngen::sqlite::database::iterator::get ( const std::string & col) const
inline

Get a column value from a row iterator by name.

Template Parameters
TType to parse value as, i.e. int
Parameters
colColumn name
Returns
T value at the named column

References find(), and get().

◆ get() [2/3]

template<typename Tp >
Tp ngen::sqlite::database::iterator::get ( int col) const

Get a column value from a row iterator by index.

Template Parameters
TType to parse value as, i.e. int
Parameters
colColumn index to parse
Returns
T value at column col

Referenced by ngen::geopackage::build_feature(), ngen::geopackage::build_geometry(), and get().

◆ get() [3/3]

auto ngen::sqlite::database::iterator::get< int > ( int col) const -> double

◆ handle_get_index_()

void ngen::sqlite::database::iterator::handle_get_index_ ( int col) const
private

◆ next()

auto ngen::sqlite::database::iterator::next ( )

Step into the next row of a SQLite query.

If the query is finished, next() acts idempotently, but will change done() to return true.

Returns
sqlite_iter& returns itself

Referenced by iterator().

◆ num_columns()

auto ngen::sqlite::database::iterator::num_columns ( ) const
noexcept

Get the number of columns within this iterator.

Returns
int number of columns in query

◆ ptr_()

auto ngen::sqlite::database::iterator::ptr_ ( ) const
privatenoexcept

Referenced by iterator().

◆ restart()

auto ngen::sqlite::database::iterator::restart ( )

Restart an iteration to its initial state.

next() must be called after calling this.

Returns
sqlite_iter& returns itself

Referenced by iterator().

◆ types()

auto ngen::sqlite::database::iterator::types ( ) const
noexcept

Get a span of column types.

See https://www.sqlite.org/datatype3.html for type affinities. The integers are the affinity for data types.

Returns
column types as a span of ints

Referenced by ngen::geopackage::build_properties().

Member Data Documentation

◆ done_

int ngen::sqlite::database::iterator::done_ = false
private

◆ names_

std::vector<std::string> ngen::sqlite::database::iterator::names_
private

Referenced by iterator().

◆ ncol_

int ngen::sqlite::database::iterator::ncol_ = 0
private

Referenced by iterator().

◆ step_

int ngen::sqlite::database::iterator::step_ = -1
private

◆ stmt_

stmt_t ngen::sqlite::database::iterator::stmt_
private

◆ types_

std::vector<int> ngen::sqlite::database::iterator::types_
private

Referenced by iterator().


The documentation for this struct was generated from the following files: