Skip to content

Commit

Permalink
Fix parsing long field values
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Aug 25, 2010
1 parent 97853a4 commit f0ce2e3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/mysql/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ Parser.prototype.write = function(buffer) {
}

packet.columnLength = lengthCoded(packet.columnLength);
if (!packet.columnLength) {

if (!packet.columnLength && !this._lengthCodedLength) {
packet.emit('data', (packet.columnLength === null ? null : new Buffer(0)), 0);
if (packet.received < packet.length) {
advance(Parser.COLUMN_VALUE_LENGTH);
Expand Down
42 changes: 42 additions & 0 deletions test/system/test-client-query-long-fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require('../common');
var Client = require('mysql').Client,
client = Client(TEST_CONFIG),
gently = new Gently();

// our test db might not exist yet, so don't try to connect to it
client.connect();

function makeString(length) {
var str = '';
for (var i = 0; i < length; i++) {
str += 'x';
}
return str;
}

var field_a = makeString(250),
field_b = makeString(251),
field_c = makeString(512),
field_d = makeString(65537);

function test(last) {
var query = client.query(
'SELECT ? as field_a, ? as field_b, ? as field_c, ? as field_d',
[field_a, field_b, field_c, field_d],
function(err, results) {
if (err) throw err;

assert.equal(results[0].field_a, field_a);
assert.equal(results[0].field_b, field_b);
assert.equal(results[0].field_c, field_c);
assert.equal(results[0].field_d, field_d);
if (last) {
client.end();
}
});
}

// We execute this test twice to be sure the parser is in a good state after
// each run.
test();
test(true);

0 comments on commit f0ce2e3

Please sign in to comment.