Sql QML Type
Contains miscellaneous Sql utilities. More...
Import Statement: | import ArcGIS.AppFramework.Sql 1.0 |
Properties
- availableDrivers : QStringList
Methods
- object connections()
Detailed Description
The Sql component provides a global object with useful utility functions for working with databases.
This code sample shows usage of the availableDrivers property, to check the available driver types against drivers used by SqlDatabase.
Item { property var driverNames: [ "QSQLITE", "QODBC", "QMYSQL", "QPSQL" ].filter(isAvailableDriver) property string driverName: "QSQLITE" property SqlDatabase dbQSQLITE: SqlDatabase { driverName: "QSQLITE" } property SqlDatabase dbQODBC: SqlDatabase { driverName: "QODBC" } property SqlDatabase dbQMYSQL: SqlDatabase { driverName: "QMYSQL" } property SqlDatabase dbQPSQL: SqlDatabase { driverName: "QPSQL" } property SqlDatabase db: this["db" + driverName] property string errorString: "" ColumnLayout { anchors.fill: parent anchors.margins: 10 TextField { id: hostNameTextField Layout.fillWidth: true placeholderText: qsTr("HostName") selectByMouse: true onTextChanged: errorString = "" } TextField { id: databaseNameTextField Layout.fillWidth: true placeholderText: qsTr("Database Name") selectByMouse: true onTextChanged: errorString = "" } TextField { id: userNameTextField Layout.fillWidth: true placeholderText: qsTr("User Name") selectByMouse: true onTextChanged: errorString = "" } TextField { id: passwordTextField Layout.fillWidth: true placeholderText: qsTr("Password") selectByMouse: true echoMode: TextInput.PasswordEchoOnEdit onTextChanged: errorString = "" } RowLayout { Layout.fillWidth: true ComboBox { id: comboBox model: driverNames onCurrentTextChanged: setDriverName(currentText) } Button { text: qsTr("Open") enabled: !db.isOpen onClicked: dbOpen() } Button { text: qsTr("Close") enabled: db.isOpen onClicked: db.close() } } TextArea { Layout.fillWidth: true Layout.fillHeight: true text: errorString readOnly: true color: "red" wrapMode: TextInput.WrapAtWordBoundaryOrAnywhere } } function isAvailableDriver(driverName) { return Sql.availableDrivers.indexOf(driverName) != -1; } function setDriverName(value) { driverName = value; hostNameTextField.text = db.hostName; databaseNameTextField.text = db.databaseName; userNameTextField.text = db.userName; passwordTextField.text = db.password; errorString = ""; } function dbOpen() { errorString = ""; db.close(); db.hostName = hostNameTextField.text; db.databaseName = databaseNameTextField.text; db.userName = userNameTextField.text; db.password = passwordTextField.text; if (!db.open()) { errorString = JSON.stringify(db.error, undefined, 2); return; } } }
Property Documentation
Returns a list of currently available driver types that your device presently supports.
Windows platforms typically support QSQLITE, QODBC, QMYSQL, and QPSQL.
macOS platforms typically support QSQLITE, QMYSQL, and QPSQL.
Android and iOS platforms typically support QSQLITE.
Note that this property only reflects Qt drivers deployed. If a Qt driver depends on a prerequisite, this prerequisite is not checked, meaning that a driver being present doesn't necessarily mean the driver will function.
Method Documentation
Returns a list of objects describing active database connections.
For each object, connectionName, connectOptions, driverName, databaseName, hostName, port, userName, isOpen and isValid are provided.