question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to run multiple statements/transaction/a sql script ?

See original GitHub issue

I know according to the protocol mysql only accept one statement a time.

But is there a way to work around it ? I tried

for(const q of script.split(';')) {
    await pool.query(q);
}

It usually works until I encountered sth. like

delimiter $$
create procedure foo
begin
select........;
end $$
delimiter ;

So, do I really need to find a way to handle this ?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sidorarescommented, Mar 8, 2020

Is it advantageous any way to await connection.query(…); await connection.query(…); ?

no, they’ll be executed sequentially anyway. There might be a benefit of doing

await Promise.all([pool.query(...), pool.query(...)])
  • that way both queries are actually might run in parallel because they are likely sent from different connections
0reactions
drwharriscommented, Feb 1, 2021

OK I think i solved it. You need to terminate each line with a \r\n

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper way to use a transaction around multiple inserts or ...
If you want to do rollback yourself, use try .. catch block. begin transaction begin try INSERT INTO TableA (id) VALUES (1) ...
Read more >
Run Multi-Statement Transactions | CockroachDB Docs
The best way to run a multi-statement transaction from Java is to write a wrapper method that automatically handles transaction retry errors.
Read more >
SQL statement sequential execution for multiple statments
After the execution of Query 1 is finished then the update query will be executed. You can run debugger to see the sequential...
Read more >
Multiple Batches in a single Transaction | Brian F Love
The solution is to use the SET XACT_ABORT ON command. This instructs SQL Server to roll back the transaction when an error occurs...
Read more >
Submitting Multiple SQL Statements in a Single Request
In the statement field, use a semicolon ( ; ) between each statement. In the parameters field, set the MULTI_STATEMENT_COUNT field to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found