Bug #84584 Unable to bind parameters
Submitted: 20 Jan 2017 13:14 Modified: 16 Mar 19:35
Reporter: William Chiquito Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connector for Node.js Severity:S2 (Serious)
Version:1.0.5 m4 OS:Any
Assigned to: CPU Architecture:Any
Tags: BIND, NodeJS, XDevAPI

[20 Jan 2017 13:14] William Chiquito
Description:
When trying to bind parameters using Connector/Node.js, the parameters are not bound.

Error:

TypeError: Cannot read property 'country' of undefined
    at data.args.criteria.placeholders.named.map.key (/user/workspace/js-test/node_modules/@mysql/xdevapi/lib/Protocol/Client.js:357:88)
    at Array.map (native)
    at Client.crudFind (/user/workspace/js-test/node_modules/@mysql/xdevapi/lib/Protocol/Client.js:357:49)
    at CollectionFind.execute (/user/workspace/js-test/node_modules/@mysql/xdevapi/lib/DevAPI/CollectionFind.js:104:10)
    at xdevapi.getSession.then.then.then.collection (/user/workspace/js-test/test.js:23:23)
    at process._tickCallback (internal/process/next_tick.js:103:7)

How to repeat:
/*
Using:
    * Node.js: v7.4.0
    * MySQL: 5.7.17
    * Schema: world_x http://downloads.mysql.com/docs/world_x-db.zip
    * Connector/Node.js: 1.0.5 m4 https://dev.mysql.com/get/Downloads/Connector-Nodejs/mysql-connector-nodejs-1.0.5.tar.gz
*/

const xdevapi = require('@mysql/xdevapi');

xdevapi.getSession({
    host: 'localhost',
    port: '33060',
    dbUser: process.env.user,
    dbPassword: process.env.password
}).then(session => {
    return session.getSchema('world_x');
}).then(schema => {
    return schema.getCollection('countryinfo');
}).then(collection => {
    /* Work
    return collection.find('$.Name == "Mexico"')
                     .execute(docs => {
                         console.log(docs);
                         process.exit();
                     });
    */
    // Not work
    return collection.find('$.Name == :country')
                     .bind({ country: 'Mexico' })
                     .execute(docs => {
                         console.log(docs);
                         process.exit();
                     });
}).catch(err => {
    console.log(err);
    process.exit();
});
[23 Jan 2017 12:43] Chiranjeevi Battula
Hello William Chiquito,

Thank you for the bug report.

Thanks,
Chiranjeevi.
[16 Mar 19:35] Rui Quelhas
Thank you for taking the time to report a problem. This has been fixed since version 8.0.7 (at least).

If you are able to reproduce the bug with one of the latest versions, please change the version on this bug report to the version you tested and change the status back to "Open".  Again, thank you for your continued support of MySQL.