Accessing an SQL database

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

Moderator: andrew

Post Reply
User avatar
andrew
Site Admin
Posts: 7181
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: 7181
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 Developers and Contributors”