Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Weird bug with prepare statement #17

Closed
halldor opened this Issue · 0 comments

2 participants

halldor Andrey Sidorov
halldor

I ran into a weird problem with prepared statements using the current tip.

The following code:

var db = require('mysql-native').createTCPClient('127.0.0.1');

db.auth('test', 'testuser', 'testpass').on('authorized', function(status) {
    console.log('connect.');
});

db.prepare('SELECT ?').on('prepared', function() {
    db.execute('SELECT ?', [1]).on('row', function(row) {
        console.log(row);
    }).on('end', function(cmd) {
        console.log('end execute');
    });
});

db.close();

Yields the error:

/usr/local/node/.npm/mysql-native/0.4.1-1-LINK-01a2e086/package/lib/mysql-native/commands/prepare.js:15
           if (this.connection.pscache[sql])
                                      ^
TypeError: Cannot read property 'SELECT ?' of undefined
    at cmd.start (/usr/local/node/.npm/mysql-native/0.4.1-1-LINK-01a2e086/package/lib/mysql-native/commands/prepare.js:15:39)
    at cmd.process_packet (/usr/local/node/.npm/mysql-native/0.4.1-1-LINK-01a2e086/package/lib/mysql-native/command.js:40:58)
    at SocketClient.dispatch_packet (/usr/local/node/.npm/mysql-native/0.4.1-1-LINK-01a2e086/package/lib/mysql-native/socketclient.js:99:32)
    at SocketClient.dispatch_packet (/usr/local/node/.npm/mysql-native/0.4.1-1-LINK-01a2e086/package/lib/mysql-native/socketclient.js:103:14)
    at Stream.<anonymous> (/usr/local/node/.npm/mysql-native/0.4.1-1-LINK-01a2e086/package/lib/mysql-native/socketclient.js:55:18)
    at Stream.emit (events:27:15)
    at IOWatcher.callback (net:484:33)
    at node.js:773:9

The error disappears if the on('prepared') is removed and the code changed to the following:

var db = require('mysql-native').createTCPClient('127.0.0.1');

db.auth('test', 'testuser', 'testpass').on('authorized', function(status) {
    console.log('connect.');
});

db.prepare('SELECT ?');
db.execute('SELECT ?', [1]).on('row', function(row) {
    console.log(row);
}).on('end', function(cmd) {
    console.log('end execute');
});


db.close();
Andrey Sidorov sidorares referenced this issue from a commit
Andrey Sidorov test for #17 09c2597
Andrey Sidorov sidorares closed this
Andrey Sidorov sidorares referenced this issue from a commit
Andrey Sidorov fixes for #16 #17 #18 #19 29e2289
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.