Skip to content

typeCast and prepared statement #390

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
LMnet opened this issue Feb 12, 2013 · 5 comments
Closed

typeCast and prepared statement #390

LMnet opened this issue Feb 12, 2013 · 5 comments

Comments

@LMnet
Copy link

LMnet commented Feb 12, 2013

I found that typeCast parameter in query didn't work with prepared statements.
Here is my example:

mysql.query(
    'SELECT * FROM `editions_schedule` WHERE `edition_id` = 1', 
    function(err, result){
        console.log(result); //works fine
});

mysql.query(
    'SELECT * FROM `editions_schedule` WHERE `edition_id` = ?', 
    [1], 
    function(err, result){
        console.log(result); //works fine
});

mysql.query(
    {
        sql: 'SELECT * FROM `editions_schedule` WHERE `edition_id` = 1', 
        typeCast: false
    }, 
    function(err, result){
        console.log(result); //works fine
});

mysql.query(
    {
        sql: 'SELECT * FROM `editions_schedule` WHERE `edition_id` = ?', 
        typeCast: false
    }, 
    [1], 
    function(err, result){
        console.log(result);
        //error:
        // TypeError: Object 1 has no method 'apply'
        // at Query.Sequence.end (/mydir/node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24)
        // at Query._handleFinalResultPacket (/mydir/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)
        // at Query.EofPacket (/mydir/node_modules/mysql/lib/protocol/sequences/Query.js:123:8)
        // at Protocol._parsePacket (/mydir/node_modules/mysql/lib/protocol/Protocol.js:169:24)
        // at Parser.write (/mydir/node_modules/mysql/lib/protocol/Parser.js:62:12)
        // at Protocol.write (/mydir/node_modules/mysql/lib/protocol/Protocol.js:36:16)
        // at Socket.ondata (stream.js:38:26)
        // at Socket.EventEmitter.emit (events.js:93:17)
        // at TCP.onread (net.js:396:14)
});
@dougwilson
Copy link
Member

You'll want to invoke it as the following:

mysql.query(
  {
    sql: 'SELECT * FROM `editions_schedule` WHERE `edition_id` = ?',
    values: [1],
    typeCast: false
  }, 
  function(err, result){
    console.log(result); //works fine
});

@LMnet
Copy link
Author

LMnet commented Feb 12, 2013

Thanks for that, but I think, at least, it must be in the manual.

@dresende
Copy link
Collaborator

Actually, it should be possible to do the way you wrote. I'm going to change .query() to allow it.

dresende added a commit that referenced this issue Feb 13, 2013
When sql was an object, the second argument was assumed as being
callback instead of checking if it could be the values.
@dresende
Copy link
Collaborator

Please try the latest git commit.

@LMnet
Copy link
Author

LMnet commented Feb 13, 2013

It works fine, thanks for help.

@LMnet LMnet closed this as completed Feb 13, 2013
dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
…h-fail-broken-pipe-error

Fixes mysqljs#389 by not sending COM_QUIT until authenticated. Also refactor…
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

3 participants