Support for multiple statements when using external SQL file
See original GitHub issueI’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:
<bountysource-plugin>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
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:9 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just throwing my two cents in.
db-migrate
is really great, but apart from deciding ifmultipleStatements
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:”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!
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.