2 #include "sq3_settings_db.hpp" 24 return this->
execute(
"delete from settings" );
29 return this->
execute(
"delete from settings " + where );
33 static std::string SettingsDb_Set_SQL =
"insert into settings values(?,?)";
37 statement st( *
this, SettingsDb_Set_SQL );
45 statement st( *
this, SettingsDb_Set_SQL );
53 statement st( *
this, SettingsDb_Set_SQL );
55 st.
bind( 2, val ? 1 : 0 );
61 statement st( *
this, SettingsDb_Set_SQL );
69 statement st( *
this, SettingsDb_Set_SQL );
77 statement st( *
this, SettingsDb_Set_SQL );
79 st.
bind( 2, val ? val :
"" );
83 int settings_db::on_open()
85 int rc = this->
execute(
"create table if not exists settings(key PRIMARY KEY ON CONFLICT REPLACE,value)" );
86 this->
execute(
"PRAGMA temp_store = MEMORY" );
87 this->
pragma(
"synchronous = OFF" );
91 static std::string SettingsDb_Get_SQL =
"select value from settings where key = ?";
97 statement st( *
this, SettingsDb_Get_SQL );
112 statement st( *
this, SettingsDb_Get_SQL );
126 statement st( *
this, SettingsDb_Get_SQL );
132 val = ( foo ?
true :
false);
146 statement st( *
this, SettingsDb_Get_SQL );
160 statement st( *
this, SettingsDb_Get_SQL );
Encapsulates a connection to an sqlite database.
int execute(const std::string &sql)
Functionally identical to execute(char const *).
settings_db()
Creates an unopened database.
int bind(int index)
Binds NULL to the given placeholder index (1-based, not 0-based!).
This class represents a prepared database statement.
virtual int open(char const *, long flags=0)
Creates/opens the given db file.
int pragma(char const *code)
This is a convenience wrapper for execute( "pragma ..." ).
virtual int clear()
Overridden to just empty the settings db.
int execute()
Assumes this object's SQL statement is a single statement.
The sq3 namespace encapsulates an OO sqlite3 API very similar to the sqlite3x API, but this one uses no exception handling (i.e., it doesn't throw on errors).
bool get(std::string const &key, int &val)
Fetches the given key from the db.
bool rc_is_okay(int rc)
rc_is_okay() is an easy way to check if rc is one of SQLITE_OK, SQLITE_ROW, or SQLITE_DONE.
void set(std::string const &key, int val)
Sets the given key/value pair.
~settings_db()
Closes this database.