Qx v0.7
Qt Extensions Library
Loading...
Searching...
No Matches
Qx Declarative SQL

Qx features a highly flexible, simple to use, declarative mechanism for querying SQL databases using user structs and other types.

For example, the following SQL table:

person:
name: VARCHAR
id: INTEGER

can easily be parsed into a list of C++ data structures like so:

#include <qx/sql/qx-sqldatabase.h>
struct person
{
QString name;
int id;
};
int main()
{
Qx::SqlDatabase myDb(u"C:/Some/db.sqlite"_s, "QSQLITE");
QList<person> allPersons;
myDb.SELECT<person>()
.FROM<person>()
.execute(allPersons);
Q_ASSERT(!err.isValid());
...
}
The SqlDatabase class provides straightforward access to an SQL database.
Definition qx-sqldatabase.h:36
The SqlError class is used to report errors related to database configuration and SQL queries.
Definition qx-sqlerror.h:21
bool isValid() const
Definition qx-sqlerror.cpp:87
The qx-sql header file offers a straightforward interface for querying an SQL database.
#define QX_SQL_STRUCT(id,...)
Definition qx-sqlquery.h:73

Likewise, the structure can used in DML queries to add data to a database:

int main()
{
...
// Add to DB
db.INSERT_INTO(person::Sql::_).VALUES<person>()
...
}

This system is accessed through the Qx SQL module, predominantly with QX_SQL_STRUCT() et al from qx-sqlquery.h, along with qx-sqlstring.h and qx-sqlinlines.h.

Database access in general is also simplified thanks to Qx::SqlDatabase.

The system still has a ways to go, but is already quite useful for a variety of basic-to-intermediate tasks.

TODO: Make this more complete.