-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial
./configure [-a "PREFIX=/usr/local"]
make
make installIf you have cppcheck and lcov installed, you might want to run make check and generate both static analysis report and code coverage overview.
If you have doxygen installed, running make doc will generate a limited documentation.
Running make flower will make your day bright. :)
All SAW is accessible via one common include #include <saw/saw.hh>
To access a database, simply create a database object, connected to the desired file.
saw::Database db("shrubbery.db"); // will raise an exception on failure
assert(db.connected());The database object has a few high-level methods that allow for simple requests to be directly executed.
db.exec("create table if not exists ni (trees int, time float);");If your query yields results, you have two options:
- some
execmethods return a vector containing all result rows in RAM; - other
execmethods expect a callback, which will be called on each row; -
resultmethods return a pair of iterators, allowing to access the results only one row at a time.
Iterating over rows is made easier with the saw_foreach macro (which is only a renamed BOOST_FOREACH).
saw_foreach (saw::Row& r, db.exec("select * from ni;"))
do_stuff(r);
saw_foreach (saw::Row& r, db.result("select * from ni;"))
do_stuff(r);A statement object can be made from the database. This allows advanced stuff like parameter binding.
saw::Statement stmt = db.make("select * from ni where trees >= @trees;");
stmt << saw::Parameter("@trees", 42);
stmt["@trees"] = 101;
stmt.exec(SAW_PLIST(("@trees", 0)));On a given row, values might be retrieved via the [] operator. It yields a value object witch might be converted to any elementary sqlite3 type.
saw::Row& row = /* ... */
std::cout << row[1].as_integer() << std::endl;No need to worry about internal memory; just allocate your objects on the stack if you desire to do so. Internal sqlite3 stuff is handled properly by reference counting.