Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: felixge/node-mysql
...
head fork: felixge/node-mysql
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 22, 2010
Felix Geisendörfer Add a basic debug mode 1072c1b
Felix Geisendörfer Add failing sequential query test 1f36260
Felix Geisendörfer Fix: Sequential queries were broken
The parser did not correctly reset itself after receiving the final EOF packet
of a result set. This patch fixes this.

Fixes issue #1: http://github.com/felixge/node-mysql/issues/#issue/1
94ce814
Felix Geisendörfer Bump version d668f10
24 lib/mysql/client.js
View
@@ -24,6 +24,7 @@ function Client(config) {
this.flags = Client.defaultFlags;
this.maxPacketSize = 0x01000000;
this.charsetNumber = 8;
+ this.debug = false;
this._queue = [];
this._connection = null;
@@ -113,6 +114,10 @@ Client.prototype.query = function(sql, params, cb) {
};
Client.prototype.write = function(packet) {
+ if (this.debug) {
+ console.log('-> %s', packet.buffer.inspect());
+ }
+
this._connection.write(packet.buffer);
};
@@ -180,6 +185,10 @@ Client.prototype._dequeue = function() {
};
Client.prototype._handlePacket = function(packet) {
+ if (this.debug) {
+ this._debugPacket(packet);
+ }
+
if (packet.type == Parser.GREETING_PACKET) {
this._sendAuth(packet);
return;
@@ -260,6 +269,21 @@ Client._packetToUserObject = function(packet) {
delete packet.errorNumber;
};
+Client.prototype._debugPacket = function(packet) {
+ var packetName = null;
+ for (var key in Parser) {
+ if (!key.match(/_PACKET$/)) {
+ continue;
+ }
+
+ if (Parser[key] == packet.type) {
+ packetName = key;
+ break;
+ }
+ }
+ console.log('<- %s: %j', packetName, packet);
+};
+
// Client Flags
Client.LONG_PASSWORD = 1;
Client.FOUND_ROWS = 2;
1  lib/mysql/parser.js
View
@@ -485,6 +485,7 @@ Parser.prototype.write = function(buffer) {
if (packet.received == 1) {
if (c === 0xfe) {
packet.type = Parser.EOF_PACKET;
+ this.receivingRowPackets = false;
advance(Parser.EOF_WARNING_COUNT);
break;
}
2  package.json
View
@@ -1,5 +1,5 @@
{ "name" : "mysql"
-, "version": "0.1.0"
+, "version": "0.2.0"
, "dependencies": {"gently": ">=0.8.0"}
, "directories" : { "lib" : "./lib/mysql" }
, "main" : "./lib/mysql/index"
2  test/simple/test-client.js
View
@@ -28,6 +28,8 @@ test(function constructor() {
assert.strictEqual(client.password, null);
assert.strictEqual(client.database, null);
+ assert.strictEqual(client.debug, false);
+
assert.strictEqual(client.flags, Client.defaultFlags);
assert.strictEqual(client.maxPacketSize, 0x01000000);
assert.strictEqual(client.charsetNumber, 8);
1  test/simple/test-parser.js
View
@@ -343,5 +343,6 @@ test(function write() {
parser.write(new Buffer([0xfe]));
assert.equal(packet.type, Parser.EOF_PACKET);
+ assert.equal(parser.receivingRowPackets, false);
})();
});
2  test/system/test-client-query-calculated-fields.js
View
@@ -10,7 +10,7 @@ client.connect();
client.query('SELECT 1 as field_a, 2 as field_b', function(err, results) {
if (err) throw err;
- console.log(results);
assert.equal(results[0].field_a, 1);
assert.equal(results[0].field_b, 2);
+ client.end();
});
22 test/system/test-client-sequential-query.js
View
@@ -0,0 +1,22 @@
+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.database = '';
+client.connect();
+
+client.query('SELECT 1 as field_a, 2 as field_b', function(err, results) {
+ if (err) throw err;
+
+ assert.equal(results[0].field_a, 1);
+ assert.equal(results[0].field_b, 2);
+});
+
+client.query('SELECT 3 as field_c', function(err, results) {
+ if (err) throw err;
+
+ assert.equal(results[0].field_c, 3);
+ client.end();
+});

No commit comments for this range

Something went wrong with that request. Please try again.