Accessing an SQL database

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Accessing an SQL database

Post by andrew » Mon Apr 20, 2020 9:29 pm

From a QCAD user:
How can I access an SQL database from my script?

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Accessing an SQL database

Post by andrew » Mon Apr 20, 2020 9:37 pm

The QCAD script interface provides access to databased through the Qt SQL module (QSqlDatabase, QSqlQuery, etc.).

This example show how to create a new database using the included SQLite driver:

Code: Select all

var db = QSqlDatabase.addDatabase("QSQLITE", "MyConnection");
db.setDatabaseName("mysql.sql");
db.open();

db.transaction();
var query = new QSqlQuery(db);
var ret = query.exec("CREATE TABLE IF NOT EXISTS MyTable (id INTEGER)");
db.commit();
For more information about the Qt SQL module, please refer to the Qt web site at:
https://doc.qt.io/qt-5/qtsql-module.html

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”