VolkovLabs / business-forms

The Business Forms panel is a conceptually new plugin for Grafana. It is the first plugin that allows inserting and updating application data, as well as modifying configuration directly from your Grafana dashboard.
https://docs.volkovlabs.io
Apache License 2.0
86 stars 10 forks source link

mysql multiple SQL queries simultaneous #311

Closed exx22 closed 5 months ago

exx22 commented 10 months ago

Hi,

Please help with creating a payload script that will simultaneously execute two SQL queries at the click of a button SQL update: UPDATE REPORTER.REPORTER_STATUS SET acknowledged = 1 WHERE serverserial='$serverserial';

SQL insert: INSERT INTO REPORTER.REPORTER_JOURNAL (chrono, userid, servername, serial, serverserial, text1) VALUES (NOW(), '\${__user.id}', 'GRAFANA', '$serverserial', '$serverserial', 'komentar');

Br, M

asimonok commented 10 months ago

You should use datasource and custom code enabled for update payload to return correct sql query

return {
  rawSql: `
UPDATE REPORTER.REPORTER_STATUS SET acknowledged = 1 WHERE serverserial='$serverserial';

INSERT INTO REPORTER.REPORTER_JOURNAL (chrono, userid, servername, serial, serverserial, text1) VALUES (NOW(), '${__user.id}', 'GRAFANA', '$serverserial', '$serverserial', 'komentar');
`,
  format: 'table',
};

Or run /ds/query yourself in the update custom code how it's described here - https://github.com/VolkovLabs/volkovlabs-form-panel/issues/279#issuecomment-1871831061

Please let us know if it works for you

RobbinDG commented 10 months ago

Hey all,

I found this issue looking to resolve this exact problem. I want to execute 2 update queries sequentially, so I have them ;-separated in the rawSql field. Attempting this query from MySQL workbench works as expected, but I get a syntax error when running it from the custom code.

An example of such a duplex query would be

return {
  rawSql: `UPDATE table_a SET column_a = ${payload.value_a}; 
UPDATE table_b SET column_b =  ${payload.value_b};`,
  format: 'table'
};

I've tried calling the queries separately from rawSql, which works in both cases. The duplex query is what breaks.

I've also attempted to print the duplex query being entered as rawSql, and sourcing it from a .sql file into the database, which also works just fine.

Any ideas or solutions?