SQL / C++ Tutorial using sqlwrapped
12. Using the generated source code
PreviousNextIndex
The generated library contains three classes; db::Player, db::Resource,
and db::Playerresource. Each class will have a few "default" constructors,
taking as the first parameter a pointer to the Database object.
For the primary key and every unique index constructors will also be
generated, to make it easy to spawn objects from the database. These
constructors will take a Database object reference as the first input
parameter.
Here are a few examples on how to spawn a Player object.
#include <sqlite3.h>
#include <libsqlitewrapped.h>
#include <libtutorialdb.h>
int main()
{
StderrLog log;
Database db("tutorial.db", &log); // sqlite3 specific
// create empty object
db::Player empty(&db);
// spawn using sql statement
db::Player anders(&db, "select * from player where name='Anders'");
// spawn using primary key
db::Player grymse(db, 2);
// spawn using unique index
db::Player lorangrym(db, "Lorangrym");
}
example8_mysql.cppexample8_sqlite3.cpp
PreviousNext