Weird bug with prepare statement #17

Closed
halldor opened this Issue Mar 9, 2011 · 0 comments

Projects

None yet

2 participants

halldor commented Mar 9, 2011

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();
@sidorares sidorares added a commit that referenced this issue Jun 6, 2011
@sidorares sidorares test for #17 09c2597
@sidorares sidorares closed this Jun 6, 2011
@sidorares sidorares added a commit that referenced this issue Jun 7, 2011
@sidorares sidorares 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