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.

multiple statements in one query doesn't works

See original GitHub issue

Issue type:

[ ] question [X] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [X] mssql [ ] mysql / mariadb [ ] oracle [ ] postgres [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[] latest [ ] @next [x] 0.2.7 (or put your version here)

Steps to reproduce or a small repository showing the problem: Hello I would like to create a query with multiple statements like this:

queryRunner.query(`CREATE TABLE IF NOT EXISTS \`pool_${this.gameId}_${index + 1}\` ` +
                    `(\`id\` int NOT NULL AUTO_INCREMENT, ` +
                    `\`hash\` varchar(255) NOT NULL, ` +
                    `\`used\` boolean NOT NULL, ` +
                    `\`index\` int NULL, ` +
                    `PRIMARY KEY (\`id\`)) ENGINE=InnoDB; ` +
                    `CREATE TABLE IF NOT EXISTS` +
                    ` \`available_pool_${this.gameId}_${index + 1}\` ` +
                    `(\`id\` int NOT NULL AUTO_INCREMENT, PRIMARY KEY (\`id\`)) ENGINE=InnoDB;`);

But i get error, if I copy that inside of mysql it executes the query correctly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
elthrashercommented, Sep 26, 2018

What’s the need to create two tables in one statement? Can’t you just

await queryRunner.query(`CREATE TABLE 1...
await queryRunner.query(`CREATE TABLE 2...

In any case, it’s possible to do this if your driver supports it, though it’s not explicitly documented in typeorm. See https://github.com/mysqljs/mysql#multiple-statement-queries You can pass these params through typeorm to the driver via the extra property: http://typeorm.io/#/connection-options/common-connection-options I realize you’re using mssql, not mysql. I glanced at the mssql docs and didn’t see support for this, but I’m not familiar with the library. I recommend just using two statements. I don’t see anything in the code above that would prohibit this.

4reactions
dancespielecommented, Sep 26, 2018

Thank you @elthrasher, if I do that works:

const connectionOptions = await getConnectionOptions();
Object.assign(connectionOptions, {multipleStatements: true});
const db = await createConnection(connectionOptions);

I know that I can do query for each statements but I want to save queries.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL Query multiple AND and OR's not working - Stack Overflow
Look at this running sql fiddle based on your schema/data/query: ... deleted AS Hat_deleted FROM modx_hats WHERE published = 1 AND ...
Read more >
Including multiple SQL statements in one query - IBM
You can include multiple SQL statements on the SQL query panel. The exceptions are CALL and CREATE PROCEDURE statements. These statements must be...
Read more >
I get the "Multiple SQL statements in a single API call are not ...
Currently, a small workaround we have is to run a bash script that will submit the SQL files from the command line, but...
Read more >
Best practices when working with Power Query - Microsoft Learn
It's entirely possible to create a single query that contains all the transformations and calculations that you may need. But if the query...
Read more >
Is it possible to include multiple SQL-Statements in one query ...
Separating the two statements is not an option because the order in which they are processed matters and manipulating query order in Power...
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