SQL / C++ Tutorial using sqlwrapped
11. Generating source code
PreviousNextIndex
Included in the Makefile are two targets, db_mysql and db_sqlite3, that
will prepare sql dumps from each database and then call sql2class to
generate the source code.
Here are the commands to dump and invoke sql2class for a MySQL database.
$ mysqldump tutorialdb > str-tutorialdb
$ sql2class -build -lib libtutorialdb str-tutorialdb -namespace db -overwrite
$
Here's the same for a sqlite3 database. The only difference is the "-sqlite"
parameter that tells sql2class to include sqlite3 header files instead of MySQL
header files.
$ sqlite3 tutorial.db .d > str-tutorialdb
$ sql2class -build -sqlite -lib libtutorialdb str-tutorialdb -namespace db -overwrite
$
The resulting files will by default be installed in /usr/devel/include and
/usr/devel/lib. The prefix "/usr/devel" can be changed with the sql2class command
line parameter "-prefix".
In the include directory will be a file named "libtutorialdb.h", and in the
lib directory the file "libtutorialdb.a" can be found.
The source code used to build the library will be in the directory
/usr/devel/src/libtutorialdb (if using default prefix /usr/devel).
PreviousNext