Skip to content

sql.Exec #258

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

Closed
wmarbut opened this issue Jul 21, 2014 · 4 comments
Closed

sql.Exec #258

wmarbut opened this issue Jul 21, 2014 · 4 comments

Comments

@wmarbut
Copy link

wmarbut commented Jul 21, 2014

  • Go Version: go version devel +c8e9255aed3f Thu Jun 05 16:40:23 2014 -0400 darwin/amd64
  • go-sql-driver Version: 1.2

When trying to run Exec with multiple statements, the engine complains about a syntax error.

e.g.

DROP TABLE IF EXISTS `table1`;
DROP TABLE IF EXISTS `table2`;
DROP TABLE IF EXISTS `table3`;
DROP TABLE IF EXISTS `table4`;

You get

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DROP TABLE IF EXISTS `table1`;
DROP TABLE IF EXISTS `table2`;
DROP TABLE IF EXISTS ' at line 2
@arnehormann
Copy link
Member

Yes, this is expected.
Multiple statements are unsupported because database/sql has no way to return multiple results and it's impossible to merge them into one.

@wmarbut
Copy link
Author

wmarbut commented Jul 21, 2014

Is there a supported way of running large scripts like importing a schema?

@arnehormann
Copy link
Member

You can split them into multiple single expressions.
If you depend on session variables you can either use a transaction or use the driver without database/sql:
session, err := mysql.Open(dsn) instead of db, err := sql.Open("mysql", dsn).

Anyway, if you haven't done so, please read http://go-database-sql.org/ first.

@wmarbut
Copy link
Author

wmarbut commented Jul 21, 2014

Thanks Arne!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants