The core of the TnFOX SQL Database Support is FX::TnFXSQLDB which is the abstract base class of SQL Database drivers in TnFOX. To use it, simply instantiate an implementation via FX::TnFXSQLDBRegistry which is the future-proof method (which in the future may load in a driver DLL).
The drivers currently provided are:
FXAutoPtr<TnFXSQLDB> mydb=TnFXSQLDBRegistry::make("SQLite3", dbname); mydb->open(); mydb->immediate("CREATE TABLE test(id INTEGER PRIMARY KEY, 'value' INTEGER, 'text' VARCHAR(256), 'when' TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"); TnFXSQLDBStatementRef s=db->prepare("SELECT :field FROM 'test' WHERE :field=:value;"); s->bind(":field", "test"); s->bind(":value", (FXint) 5); for(TnFXSQLDBCursorRef c=s->execute(); !c->atEnd(); c->next()) { fxmessage("Entry %d: %d\n", c->at(), c->data(0)->get<FXint>(v)); }
db->execute()
directly. However, there is an important caveat - if you place values directly into a string, you must escape them in a SQL92 compatible way which isn't required if you simply bind in the values.To give you some idea of the power of TnFOX, this is from the AllTests application in the Test suite:
// No other C++ toolkit can bz2 decompress from a SQL query BLOB in so little code!
QByteArray blob;
cur->data(7)->get<>(blob);
QBuffer buff(blob);
QBZip2Device bz2(&buff);
bz2.open(IO_ReadOnly);
FXStream s(&bz2);
s >> output;
TODO:
Classes | |
class | FX::TnFXSQLDB |
The abstract base class of a SQL database driver. More... | |
class | FX::TnFXSQLDBTransaction |
Manages a SQL database transaction. More... | |
class | FX::TnFXSQLDBCursor |
Abstract base class for a cursor which can iterate through the results of executing a statement. More... | |
class | FX::TnFXSQLDBStatement |
The abstract base class of a prepared SQL statement. More... | |
class | FX::TnFXSQLDBColumn |
Represents information about a column in a row. More... | |
class | FX::TnFXSQLDBRegistry |
Knows of all currently available FX::TnFXSQLDB's. More... | |
class | FX::TnFXSQLDB_ipc |
A SQL database driver for a FX::FXIPCChannel. More... | |
class | FX::TnFXSQLDB_sqlite3 |
A SQL database driver for SQLite3. More... |