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.

Support for multiple statements when using external SQL file

See original GitHub issue

I’ve setup my database.json — which is definitely being used — to specify multipleStatements: true:

{
    "mysql": {
        "ENV": "DB_CREDENTIALS",
        "multipleStatements": true,
        "native": true
    }
}

However, when I try to migrate the following SQL migration — which was created by using db-migrate create add-quotes --sql-file -e mysql — I get an error that suggests multiple statements aren’t supported when using --sql-file:

CREATE TABLE `cocktails` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
  `slug` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
  `description` mediumtext COLLATE utf8_unicode_ci,
  `date_added` date DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `quotes` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `quote` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Which produces the following error:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘CREATE TABLE quotes ( id int(11) unsigned NOT NULL AUTO_INCREMENT, `quot’ at line 10

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
bhubrcommented, Jul 23, 2019

Just throwing my two cents in. db-migrate is really great, but apart from deciding if multipleStatements should be made a default, there is definitely, IMHO, a documentation issue.

The usage page mentions the --sql-file, and states that “the sql files will have the following content:”

/* Replace with your SQL commands */

Now, correct me if I’m wrong, but SQL commands seems to imply that you may put several of them, which I incorrectly assumed. So I lost a fair amount of time trying to fix an SQL schema that wasn’t broken, just because I got the exact same error as the OP when trying to import a schema.

It might be worth mentioning, in the auto-generated SQL files, that issuing multiple statements without specifying multipleStatements will result in errors!

5reactions
captainamericancommented, Sep 22, 2018

If you’re using the DATABASE_URL environmental variable, you can bypass this bug in the following manner:

mysql://user:pass@host/database?multipleStatements=true

I’m don’t why this works. It was a last ditch effort before I got rid of db-migrate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
python - Execute SQL file with multiple statements separated ...
The API in the pyodbc connector (or pymysql) doesn't allow multiple statements in a SQL call. This is an issue of engine parsing; ......
Read more >
sqlFile | Liquibase Docs
<sqlFile> supports multiple SQL statements in the same file: Single-line SQL statements can be separated using a ; at the end of the...
Read more >
"how can execute multiple sql file using snowsql ...
how can execute multiple sql file using snowsql (commandline utility). I am using following code for single sql file. (snowsql -c cc -f...
Read more >
4.5.1.5 Executing SQL Statements from a Text File
If you are already running mysql, you can execute an SQL script file using the source command or \. command: mysql> source file_name...
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