Skip to content

Multiple SELECT statements don't work #736

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
coulson84 opened this issue Feb 19, 2014 · 2 comments
Closed

Multiple SELECT statements don't work #736

coulson84 opened this issue Feb 19, 2014 · 2 comments

Comments

@coulson84
Copy link

I am having some issues with multiple statements. I am trying to insert a row then select from the same database but I am being told that there is an error in my second statement but there is not. They work when entered in via phpmyadmin interface but fail when used in node. I have tried dumming the multiple select down to its most basic level (the example given in the readme in fact) but am still seeing the same error.

var mysql = require('mysql');
var connection = mysql.createConnection(properties);

connection.query('SELECT 1; SELECT 2;', function(){
console.log(arguments);
});

=> { '0':
{ [Error: ER_PARSE_ERROR: 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 'SELECT 2' at line 1]
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '42000',
index: 0 },
'1': undefined,
'2': undefined }

Any pointers/reasons for this?

Thanks
Joe

@dougwilson
Copy link
Member

Hello! In order to use multiple statements in a single query (each statement is separated with a ;) you need to set multipleStatements to true in your configuration.

Example from what you pasted:

var mysql = require('mysql');

properties.multipleStatements = true; // <-- this needs to be set

var connection = mysql.createConnection(properties);

connection.query('SELECT 1; SELECT 2;', function(){
console.log(arguments);
});

@coulson84
Copy link
Author

Fantastic. :) I must have missed that in the documentation.

Thanks for the quick reply,

Joe

On 19/02/14 14:01, Douglas Christopher Wilson wrote:

Closed #736#736.


Reply to this email directly or view it on GitHubhttps://github.com//issues/736.

dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants