Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: felixge/node-mysql
...
head fork: felixge/node-mysql
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 22, 2010
@felixge Add a basic debug mode 1072c1b
@felixge Add failing sequential query test 1f36260
@felixge 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
@felixge Bump version d668f10
View
24 lib/mysql/client.js
@@ -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;
View
1  lib/mysql/parser.js
@@ -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;
}
View
2  package.json
@@ -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"
View
2  test/simple/test-client.js
@@ -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);
View
1  test/simple/test-parser.js
@@ -343,5 +343,6 @@ test(function write() {
parser.write(new Buffer([0xfe]));
assert.equal(packet.type, Parser.EOF_PACKET);
+ assert.equal(parser.receivingRowPackets, false);
})();
});
View
2  test/system/test-client-query-calculated-fields.js
@@ -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();
});
View
22 test/system/test-client-sequential-query.js
@@ -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.