Sqlitepp  1.2.3
A thin sqlite C++ wrapper
Classes | Public Member Functions | List of all members
sqlite::Connection Class Referencefinal

Sqlite database connection. More...

#include <sqlite.hpp>

Classes

struct  Column_metadata
 Column metadata info. More...
 
class  Stmt
 Prepared statement obj - usually created by Connection::create_statement. More...
 

Public Member Functions

 Connection (const std::string &filename)
 Open / create new DB. More...
 
 Connection (const Connection &)=delete
 
Connectionoperator= (const Connection &)=delete
 
 Connection (Connection &&)
 
Connectionoperator= (Connection &&)
 
Stmt create_statement (const std::string &sql)
 Create a new prepared statement. More...
 
void exec (const std::string &sql, int(*callback)(void *, int, char **, char **)=nullptr, void *arg=nullptr)
 Execute SQL statement(s) More...
 
void begin_transaction ()
 Start a transaction. More...
 
void commit ()
 End a transaction & commit. More...
 
void rollback ()
 End a transaction & rollback. More...
 
void interrupt ()
 Interrupt a long-running query. More...
 
sqlite3_int64 last_insert_rowid ()
 Get last INSERTed Row ID. More...
 
int total_changes ()
 Get total number of rows modified. More...
 
Column_metadata table_column_metadata (const std::string &table_name, const std::string &column_name, const std::string &db_name="main")
 Get column metadata. More...
 
const sqlite3 * get_c_obj () const
 Get wrapped C sqlite3 object (for use with the sqlite C API) More...
 
sqlite3 * get_c_obj ()
 Get wrapped C sqlite3 object (for use with the sqlite C API) More...
 

Detailed Description

Sqlite database connection.

Holds a connection to a database. SQL may be run with either the exec() method, or by using create_statement() to build a Connection::Stmt object

See also
C API

Constructor & Destructor Documentation

◆ Connection()

sqlite::Connection::Connection ( const std::string &  filename)
explicit

Open / create new DB.

Parameters
[in]filenamePath to sqlite database file
Exceptions
Runtime_erroron error connecting to DB
See also
C API

Member Function Documentation

◆ create_statement()

Connection::Stmt sqlite::Connection::create_statement ( const std::string &  sql)

Create a new prepared statement.

Parameters
[in]sqlSQL code to prepare
Returns
Prepared statement for the SQL code input
Exceptions
Logic_erroron error parsing SQL
See also
C API

◆ exec()

void sqlite::Connection::exec ( const std::string &  sql,
int(*)(void *, int, char **, char **)  callback = nullptr,
void *  arg = nullptr 
)

Execute SQL statement(s)

Will execute the SQL in-place, without needing to create a Connection::Stmt object.

Parameters
[in]sqlSQL code to execute
[in]callbackFunction to call for every row. May be NULL. Parameters are:
  • arg: The arg parameter from the exec call
  • column_data: Array of column data (as strings) for the current row
  • column_names: Array of column names
[in,out]argData to pass as 1st arg of callback. May be NULL.
Exceptions
Logic_erroron error evaluating SQL
See also
C API

◆ begin_transaction()

void sqlite::Connection::begin_transaction ( )

Start a transaction.

See also
C API

◆ commit()

void sqlite::Connection::commit ( )

End a transaction & commit.

See also
C API

◆ rollback()

void sqlite::Connection::rollback ( )

End a transaction & rollback.

See also
C API

◆ interrupt()

void sqlite::Connection::interrupt ( )

Interrupt a long-running query.

See also
C API

◆ last_insert_rowid()

sqlite3_int64 sqlite::Connection::last_insert_rowid ( )

Get last INSERTed Row ID.

@ returns Row ID for last INSERTed row

See also
C API

◆ total_changes()

int sqlite::Connection::total_changes ( )

Get total number of rows modified.

Returns
Total number of rows inserted, modified or deleted by all INSERT, UPDATE or DELETE statements completed since the database connection was opened, including those executed as part of trigger programs.
See also
C API

◆ table_column_metadata()

Connection::Column_metadata sqlite::Connection::table_column_metadata ( const std::string &  table_name,
const std::string &  column_name,
const std::string &  db_name = "main" 
)

Get column metadata.

Parameters
[in]table_nameTable name
[in]column_nameColumn name
[in]db_nameDB name, or "main" if omitted
Returns
The chosen column's metadata
Exceptions
Runtime_erroron error looking up info
See also
C API

◆ get_c_obj() [1/2]

const sqlite3 * sqlite::Connection::get_c_obj ( ) const

Get wrapped C sqlite3 object (for use with the sqlite C API)

Returns
C sqlite3 object

◆ get_c_obj() [2/2]

sqlite3 * sqlite::Connection::get_c_obj ( )

Get wrapped C sqlite3 object (for use with the sqlite C API)

Returns
C sqlite3 object

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