Here is a working example using the recommended prepared statement functions: 1. Publish the HMI (if already existing) 2. Create the desired table in custom.sqlite manually, e.g. using SQLiteStudio: 3. Create prepared statements in the file .db/statements.json of the project: {
"statements": [
{
"conditions": [],
"deferred": true,
"description": "",
"sql": "INSERT INTO test ([val]) VALUES (:val);",
"statementName": "test_insert",
"targetDatabase": "custom"
},
{
"conditions": [],
"deferred": true,
"description": "",
"sql": "SELECT * FROM test",
"statementName": "test_select_all",
"targetDatabase": "custom"
}
],
"version": 0
} 4. Load the HMI in WebIQ Designer and create a new UI Action: actions["dbAction"] = function(parameters) {
const value = parameters[0],
qm = shmi.visuals.session.QueryManager;
console.log('[UI:dbAction] ' + value);
qm.executePreparedStatement('test_insert', { 'val' : value }, function(error, data) {
if (error) {
console.error(error);
} else {
console.log(`Inserted with id ${data.last_insert_id}`);
// Dump all
qm.executePreparedStatement('test_select_all', {}, function(error, data) {
if (error) {
console.error(error);
} else {
console.log(data.rows);
}
});
}
});
}; When you now add the UI Action to a button you can insert data into the table: The UI Action will also show all entries in the database table on the console after insertion. The method is documented here: https://www.smart-hmi.com/user/download/deliver/docs/documentation-webiq-visuals-reference-2.15-ee64/shmi.visuals.core.QueryManager.html#executePreparedStatement__anchor I have attached the HMI (2.15.4).
... View more