SQLiteXX  0.1.0
 All Classes Namespaces Files Functions Enumerations Enumerator
Public Member Functions | Static Public Member Functions | List of all members
sqlite::dbconnection Class Reference

Class that represents a connection to a database. More...

#include <DBConnection.h>

Public Member Functions

 dbconnection () noexcept
 Default constructor.
 
 dbconnection (const dbconnection &other) noexcept
 Copy constructor. More...
 
 dbconnection (dbconnection &&other) noexcept
 Copy constructor. More...
 
 dbconnection (const std::string &filename, openmode mode=openmode::read_write|openmode::create, const std::chrono::milliseconds timeout=DEFAULT_TIMEOUT)
 Open the provided database UTF-8 filename. More...
 
 dbconnection (const std::string &filename, const std::chrono::milliseconds timeout)
 Open the provided database UTF-8 filename. More...
 
 dbconnection (const std::u16string &filename, const std::chrono::milliseconds timeout=DEFAULT_TIMEOUT)
 Open the provided database UTF-16 filename. More...
 
dbconnectionoperator= (const dbconnection &other) noexcept
 Copy assignment operator. More...
 
dbconnectionoperator= (dbconnection &&other) noexcept
 Move assignment operator. More...
 
sqlite::mutex mutex ()
 Returns a mutex that serializes access to the database. More...
 
 operator bool () const noexcept
 Specifies if the dbconnection has a open database connection. More...
 
sqlite3 * handle () const noexcept
 Returns pointer to the underlying "sqlite3" object.
 
void open (const std::string &filename, openmode mode=openmode::read_write|openmode::create)
 Open an SQLite database file as specified by the filename argument. More...
 
void open (const std::u16string &filename)
 Open an SQLite database file as specified by the filname argument. More...
 
long long row_id () const noexcept
 Returns the rowid of the most recent successful "INSERT" into a rowid table or virtual table on database connection. More...
 
template<typename F >
void create_general_function (const std::string &name, F &&function, int is_deterministic=false, const textencoding encoding=textencoding::utf8, int nargs=-1)
 Used to add SQL functions or redefine the behavior of existing SQL functions. More...
 
template<typename F >
void create_function (const std::string &name, F &&function, bool is_deterministic=false, const textencoding encoding=textencoding::utf8)
 Used to add SQL functions or redefine the behavior of existing SQL functions. More...
 
template<typename A >
void create_aggregate (const std::string &name, bool is_deterministic=false, const textencoding encoding=textencoding::utf8)
 Used to add SQL aggregate functions or redefine the behavior of existing SQL aggregate functions. More...
 
template<typename F >
void create_collation (const std::string &name, F &&function, const textencoding encoding=textencoding::utf8)
 Used to add an SQL collation or redefine the behavior of existing SQL collations. More...
 

Static Public Member Functions

static dbconnection memory ()
 Create a purely in memory database. More...
 
static dbconnection wide_memory ()
 Create a purely in memory database with UTF-16 as the native byte order. More...
 

Detailed Description

Class that represents a connection to a database.

The class dbconnection is a wrapper around the "sqlite3" structure.

Definition at line 24 of file DBConnection.h.

Constructor & Destructor Documentation

sqlite::dbconnection::dbconnection ( const dbconnection other)
noexcept

Copy constructor.

Parameters
[in]otheranother dbconnection object to use as source to initialize object with.

Definition at line 11 of file DBConnection.cpp.

sqlite::dbconnection::dbconnection ( dbconnection &&  other)
noexcept

Copy constructor.

Constructs a dbconnection object with a copy of the contents of other using move semantics.

Parameters
[in]otheranother dbconnection object to use as source to initialize object with.

Definition at line 15 of file DBConnection.cpp.

sqlite::dbconnection::dbconnection ( const std::string &  filename,
openmode  mode = openmode::read_write | openmode::create,
const std::chrono::milliseconds  timeout = DEFAULT_TIMEOUT 
)

Open the provided database UTF-8 filename.

Parameters
[in]filenameUTF-8 path/uri to the database database file
[in]modefile opening options specified by combination of openmode flags
[in]timeoutamount of milliseconds to wait before returning sqlite::busy_exception when a table is locked

Definition at line 35 of file DBConnection.cpp.

sqlite::dbconnection::dbconnection ( const std::string &  filename,
const std::chrono::milliseconds  timeout 
)

Open the provided database UTF-8 filename.

Parameters
[in]filenameUTF-8 path/uri to the database database file
[in]timeoutamount of milliseconds to wait before returning sqlite::busy_exception when a table is locked

Definition at line 44 of file DBConnection.cpp.

sqlite::dbconnection::dbconnection ( const std::u16string &  filename,
const std::chrono::milliseconds  timeout = DEFAULT_TIMEOUT 
)

Open the provided database UTF-16 filename.

Parameters
[in]filenameUTF-16 path/uri to the database database file
[in]timeoutAmount of milliseconds to wait before returning sqlite::busy_exception when a table is locked

Definition at line 52 of file DBConnection.cpp.

Member Function Documentation

template<typename A >
void sqlite::dbconnection::create_aggregate ( const std::string &  name,
bool  is_deterministic = false,
const textencoding  encoding = textencoding::utf8 
)
inline

Used to add SQL aggregate functions or redefine the behavior of existing SQL aggregate functions.

Template Parameters
AThe class to use as the aggregate function.
Parameters
[in]namethe name of the aggregate function to be used in an SQL query
[in]is_deterministicspecifies if the function will always return the same result given the same inputs within a single SQL statement.
[in]encodingspecifies the test encoding the SQL function prefers for its parameters

Definition at line 203 of file DBConnection.h.

template<typename F >
void sqlite::dbconnection::create_collation ( const std::string &  name,
F &&  function,
const textencoding  encoding = textencoding::utf8 
)
inline

Used to add an SQL collation or redefine the behavior of existing SQL collations.

The function created should not throw an exception, if so the results is unknown.

Template Parameters
FThe function type to use to create the function.
Parameters
[in]namethe name of the function to be used in an SQL query
[in]functionthe implementation to the function
[in]encodingspecifies the test encoding the SQL function prefers for its parameters

Definition at line 239 of file DBConnection.h.

template<typename F >
void sqlite::dbconnection::create_function ( const std::string &  name,
F &&  function,
bool  is_deterministic = false,
const textencoding  encoding = textencoding::utf8 
)
inline

Used to add SQL functions or redefine the behavior of existing SQL functions.

Template Parameters
FThe function type to use to create the function.
Parameters
[in]namethe name of the function to be used in an SQL query
[in]functionthe implementation to the function
[in]is_deterministicspecifies if the function will always return the same result given the same inputs within a single SQL statement.
[in]encodingspecifies the test encoding the SQL function prefers for its parameters

Definition at line 168 of file DBConnection.h.

template<typename F >
void sqlite::dbconnection::create_general_function ( const std::string &  name,
F &&  function,
int  is_deterministic = false,
const textencoding  encoding = textencoding::utf8,
int  nargs = -1 
)
inline

Used to add SQL functions or redefine the behavior of existing SQL functions.

Template Parameters
FThe function type to use to create the function.
Parameters
[in]namethe name of the function to be used in an SQL query
[in]functionthe implementation to the function
[in]is_deterministicspecifies if the function will always return the same result given the same inputs within a single SQL statement.
[in]encodingspecifies the text encoding the SQL function prefers for its parameters.
[in]nargsthe number of arguments that the SQL function takes. -1 means the SQL function can take any number of arguments.

Definition at line 131 of file DBConnection.h.

dbconnection sqlite::dbconnection::memory ( )
static

Create a purely in memory database.

Returns
a purely in memory sqlite::dbconnection

Definition at line 60 of file DBConnection.cpp.

mutex sqlite::dbconnection::mutex ( )

Returns a mutex that serializes access to the database.

Returns
A mutex object for the database connection.

Definition at line 70 of file DBConnection.cpp.

void sqlite::dbconnection::open ( const std::string &  filename,
openmode  mode = openmode::read_write | openmode::create 
)

Open an SQLite database file as specified by the filename argument.

Parameters
[in]filenamepath to SQLite file
[in]modespecifies the privileges to use when opening the database.

Definition at line 89 of file DBConnection.cpp.

void sqlite::dbconnection::open ( const std::u16string &  filename)

Open an SQLite database file as specified by the filname argument.

The database file will have UTF-16 native byte order.

Parameters
[in]filenamepath to SQLite file

Definition at line 101 of file DBConnection.cpp.

sqlite::dbconnection::operator bool ( ) const
explicitnoexcept

Specifies if the dbconnection has a open database connection.

Returns
Returns true if the dbconnection has a open database connection associated associated with it.

Definition at line 79 of file DBConnection.cpp.

dbconnection & sqlite::dbconnection::operator= ( const dbconnection other)
noexcept

Copy assignment operator.

Replaces the contents with those of other.

Parameters
[in]otheranother dbconnection object to use as source to initialize object with.
Returns
*this

Definition at line 19 of file DBConnection.cpp.

dbconnection & sqlite::dbconnection::operator= ( dbconnection &&  other)
noexcept

Move assignment operator.

Replaces the contents with those of other using move semantics.

Parameters
[in]otheranother dbconnection object to use as source to initialize object with.
Returns
*this

Definition at line 28 of file DBConnection.cpp.

long long sqlite::dbconnection::row_id ( ) const
noexcept

Returns the rowid of the most recent successful "INSERT" into a rowid table or virtual table on database connection.

Returns
rowid of the most recent successful "INSERT" into the database, or 0 if there was none.

Definition at line 113 of file DBConnection.cpp.

dbconnection sqlite::dbconnection::wide_memory ( )
static

Create a purely in memory database with UTF-16 as the native byte order.

Returns
a purely in memory sqlite::dbconnection

Definition at line 65 of file DBConnection.cpp.


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