felixge/node-mysql — Issue #163: Cannot INSERT binary data to BLOBs
Author: JulesAU
Created: 2012-01-24 04:07:11+00:00
State: open

Expected behavior: Buffer objects should be appropriately escaped to allow use in INSERT/UPDATE queries.

Observed behavior: Buffers appear to be cast to UTF-8 strings first, causing corruption.

Test case:

````javascript

var mysql = require('mysql');
var mysqlClient = mysql.createClient({'user': 'test', 'password': 'test'/*, 'port': mysqlSocket*/});

mysqlClient.useDatabase('test', function (err) {
mysqlClient.query('CREATE TABLE IF NOT EXISTS nodetest (id int not null primary key, data blob) CHARSET=binary', function (err) {

var binaryData = new Buffer('00AA27FFBDA935645CD5476AB56DE67FA6', 'hex');
console.log(binaryData);
mysqlClient.query('REPLACE INTO nodetest VALUES (1, ?)', [binaryData], function (err) {
mysqlClient.query('SELECT data FROM nodetest', function (err, results, fields) {
console.log(results);
mysqlClient.end();

})
})
});
})
````

And to verify:

````shell
echo 'select hex(data) from nodetest' | mysql test;
````