#include <sq3_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. | |
virtual int | clear () |
Overridden to just empty the settings db. | |
int | 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). |
It is intended to be used as a simple config-file class.
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.
When doing lots of set() calls you can gain a lot of speed by adding an sq3::transaction before you start and calling commit() on that transaction when you're done.
Definition at line 32 of file sq3_settings_db.hpp.
sq3::settings_db::settings_db | ( | std::string const & | dbname | ) | [explicit] |
Calls open(dbname).
Use is_open() to find out if the open succeeded.
Definition at line 12 of file sq3_settings_db.cpp.
References sq3::database::open().
sq3::settings_db::settings_db | ( | ) |
Creates an unopened database.
You must call open() before you can use this object.
Definition at line 7 of file sq3_settings_db.cpp.
int sq3::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 27 of file sq3_settings_db.cpp.
References sq3::database::execute().
int sq3::settings_db::clear | ( | ) | [virtual] |
Overridden to just empty the settings db.
Does not remove the db file. Returns SQLITE_OK on success, else false.
Reimplemented from sq3::database.
Definition at line 22 of file sq3_settings_db.cpp.
References sq3::database::execute().
bool sq3::settings_db::get | ( | std::string const & | key, | |
std::string & | val | |||
) |
See get(string,int).
Definition at line 156 of file sq3_settings_db.cpp.
References sq3::statement::bind(), sq3::statement::execute(), and sq3::rc_is_okay().
bool sq3::settings_db::get | ( | std::string const & | key, | |
double & | val | |||
) |
See get(string,int).
Definition at line 142 of file sq3_settings_db.cpp.
References sq3::statement::bind(), sq3::statement::execute(), and sq3::rc_is_okay().
bool sq3::settings_db::get | ( | std::string const & | key, | |
bool & | val | |||
) |
See get(string,int).
Definition at line 122 of file sq3_settings_db.cpp.
References sq3::statement::bind(), sq3::statement::execute(), and sq3::rc_is_okay().
bool sq3::settings_db::get | ( | std::string const & | key, | |
sqlite_int64 & | val | |||
) |
See get(string,int).
Definition at line 108 of file sq3_settings_db.cpp.
References sq3::statement::bind(), sq3::statement::execute(), and sq3::rc_is_okay().
bool sq3::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 93 of file sq3_settings_db.cpp.
References sq3::statement::bind(), sq3::statement::execute(), and sq3::rc_is_okay().