The Xql3 class was intended to be quick and easy to program as well as to use. The basic idea was to get a minimal interface into sqlite3 from C++. The documentation for sqlite3 states that it only takes 3 steps to use sqlite via the C API: sqlite3_open, sqlite3_exec and sqlite3_close. The issue here is that it appears that "exec" usage has been deprecated with a preference for "sqlite3_prepare_v2" and "sqlite3_step" ... Therefore this class aimed to maintain that easy interface (ie: minimal interface calls). This is achieved by implementing an "exec" that does the sqlite3_prepare_v2 and sqlite3_step while providing a C++ style callback -- by overriding a virtual callback. And if the database is passed to the constructor, there is no need to do an explicit call to sqlite3_open and the class destructor does what is necessary to close the database -- so, in theory, this interface has only 1 call "Xql3::exec" which takes a std::string containing one or more SQL statements to execute -- although the examples do use an explicit call to open only because of declaring a variable outside of the try/catch block.

Interface and use

The class is implemented in Xql3.cpp, the exception class is defined in Xql3Exception.h.

Using the class is fairly straight forward as demonstrated by the two example test programs. xql3_tester_v1a.cpp uses the default Xql3 callback to put results into a vector of strings as part of the Xql3 class object. xql3_tester_v1b.cpp extends class Xql3 and overrides the callback -- although it also just puts the result into a vector, the vector is in the extended class and not the base Xql3 class. The point is that the extended class could have just counted the lines or done something else other than just put the results into a vector of strings.


Browse all code for this this class ...