sqlite3x::settings_db Class Reference

settings_db ia a very simplistic settings-data database for use with the sqlite3x database layer. More...

#include <sqlite3x_settings_db.hpp>

List of all members.

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_connectiondb ()
 If you want low-level info about the db, here's the handle to it.

Detailed Description

settings_db ia a very simplistic settings-data database for use with the sqlite3x database layer.

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 25 of file sqlite3x_settings_db.hpp.


Constructor & Destructor Documentation

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 10 of file sqlite3x_settings_db.cpp.

sqlite3x::settings_db::settings_db (  ) 

Creates an unopened database.

You must call open() before you can use this object.

Definition at line 5 of file sqlite3x_settings_db.cpp.


Member Function Documentation

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 54 of file sqlite3x_settings_db.cpp.

void sqlite3x::settings_db::clear (  ) 

Empties the database.

Does not remove the db file.

Definition at line 49 of file sqlite3x_settings_db.cpp.

void sqlite3x::settings_db::close (  ) 

Closes this database.

Not normally necessary, as this happens during the destruction of this object.

Definition at line 39 of file sqlite3x_settings_db.cpp.

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 60 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 181 of file sqlite3x_settings_db.cpp.

bool sqlite3x::settings_db::get ( std::string const &  key,
double &  val 
)

See get(string,int).

Definition at line 167 of file sqlite3x_settings_db.cpp.

bool sqlite3x::settings_db::get ( std::string const &  key,
bool &  val 
)

See get(string,int).

Definition at line 153 of file sqlite3x_settings_db.cpp.

bool sqlite3x::settings_db::get ( std::string const &  key,
sqlite_int64 &  val 
)

See get(string,int).

Definition at line 139 of file sqlite3x_settings_db.cpp.

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 124 of file sqlite3x_settings_db.cpp.

References sqlite3x::sqlite3_command::bind(), and sqlite3x::sqlite3_command::executeint().


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208