Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql multiple SQL queries simultaneous #311

Closed
exx22 opened this issue Dec 13, 2023 · 2 comments · Fixed by #361
Closed

mysql multiple SQL queries simultaneous #311

exx22 opened this issue Dec 13, 2023 · 2 comments · Fixed by #361
Assignees
Labels
question Further information is requested

Comments

@exx22
Copy link

exx22 commented Dec 13, 2023

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

@mikhail-vl mikhail-vl self-assigned this Dec 13, 2023
@mikhail-vl mikhail-vl added the question Further information is requested label Dec 13, 2023
@asimonok
Copy link
Collaborator

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 - #279 (comment)

Please let us know if it works for you

@RobbinDG
Copy link

RobbinDG commented Jan 2, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

Successfully merging a pull request may close this issue.

4 participants