#include <sqlite3x_settings_db.hpp>
Public Member Functions | |
settings_db (std::string const &dbname) | |
Calls open(dbname). | |
settings_db () | |
Creates an unopened database. | |
~settings_db () | |
Closes this database. | |
bool | is_open () const |
Returns true if open() has succeeded. | |
void | clear () |
Empties the database. | |
void | clear (std::string const &where) |
Empties the database items matching the given WHERE clause. | |
void | set (std::string const &key, int val) |
Sets the given key/value pair. | |
void | set (std::string const &key, sqlite_int64 val) |
Sets the given key/value pair. | |
void | set (std::string const &key, bool val) |
Sets the given key/value pair. | |
void | set (std::string const &key, double val) |
Sets the given key/value pair. | |
void | set (std::string const &key, std::string const &val) |
Sets the given key/value pair. | |
void | set (std::string const &key, char const *val) |
Sets the given key/value pair. | |
bool | get (std::string const &key, int &val) |
Fetches the given key from the db. | |
bool | get (std::string const &key, sqlite_int64 &val) |
See get(string,int). | |
bool | get (std::string const &key, bool &val) |
See get(string,int). | |
bool | get (std::string const &key, double &val) |
See get(string,int). | |
bool | get (std::string const &key, std::string &val) |
See get(string,int). | |
void | open (std::string const &dbname) |
Opens the database dbname or throws on error. | |
void | close () |
Closes this database. | |
sqlite3_connection * | db () |
If you want low-level info about the db, here's the handle to it. |
Usage:
settings_db db("my.db"); db.set("one", 1 ); db.set("two", 2.0 ); db.set("a_string", "a string" );
std::string sval; assert( db.get( "a_string", sval ) );
Obviously, an assert may be too harsh for what you're doing.
Definition at line 26 of file sqlite3x_settings_db.hpp.
sqlite3x::settings_db::settings_db | ( | std::string const & | dbname | ) | [explicit] |
Calls open(dbname).
This ctor will throw if dbname cannot be opened or if it is not a database.
Definition at line 12 of file sqlite3x_settings_db.cpp.
References open().
sqlite3x::settings_db::settings_db | ( | ) |
Creates an unopened database.
You must call open() before you can use this object.
Definition at line 7 of file sqlite3x_settings_db.cpp.
void sqlite3x::settings_db::clear | ( | std::string const & | where | ) |
Empties the database items matching the given WHERE clause.
Does not remove the db file.
'where' should be a full SQL where statement, e.g.:
"WHERE KEY LIKE 'x%'"
The field names in this db are KEY and VALUE.
Definition at line 56 of file sqlite3x_settings_db.cpp.
References sqlite3x::sqlite3_connection::executenonquery().
void sqlite3x::settings_db::clear | ( | ) |
Empties the database.
Does not remove the db file.
Definition at line 51 of file sqlite3x_settings_db.cpp.
References sqlite3x::sqlite3_connection::executenonquery().
void sqlite3x::settings_db::close | ( | ) |
Closes this database.
Not normally necessary, as this happens during the destruction of this object.
Definition at line 41 of file sqlite3x_settings_db.cpp.
References sqlite3x::sqlite3_connection::close().
Referenced by open(), and ~settings_db().
sqlite3_connection * sqlite3x::settings_db::db | ( | ) |
If you want low-level info about the db, here's the handle to it.
This will be null before open() has succeeded.
Definition at line 62 of file sqlite3x_settings_db.cpp.
bool sqlite3x::settings_db::get | ( | std::string const & | key, | |
std::string & | val | |||
) |
See get(string,int).
Definition at line 183 of file sqlite3x_settings_db.cpp.
References sqlite3x::sqlite3_command::bind(), and sqlite3x::sqlite3_command::executestring().
bool sqlite3x::settings_db::get | ( | std::string const & | key, | |
double & | val | |||
) |
See get(string,int).
Definition at line 169 of file sqlite3x_settings_db.cpp.
References sqlite3x::sqlite3_command::bind(), and sqlite3x::sqlite3_command::executedouble().
bool sqlite3x::settings_db::get | ( | std::string const & | key, | |
bool & | val | |||
) |
See get(string,int).
Definition at line 155 of file sqlite3x_settings_db.cpp.
References sqlite3x::sqlite3_command::bind(), and sqlite3x::sqlite3_command::executeint().
bool sqlite3x::settings_db::get | ( | std::string const & | key, | |
sqlite_int64 & | val | |||
) |
See get(string,int).
Definition at line 141 of file sqlite3x_settings_db.cpp.
References sqlite3x::sqlite3_command::bind(), and sqlite3x::sqlite3_command::executeint64().
bool sqlite3x::settings_db::get | ( | std::string const & | key, | |
int & | val | |||
) |
Fetches the given key from the db.
If it is found, it is converted to the data type of val, val is assigned that value, and true is returned. If false is returned then val is unchanged.
Definition at line 126 of file sqlite3x_settings_db.cpp.
References sqlite3x::sqlite3_command::bind(), and sqlite3x::sqlite3_command::executeint().