diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index 412688728..5957b7929 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -116,6 +116,8 @@ function typeCast(field, parser, timeZone, supportBigNumbers, bigNumberStrings, : parser.parseLengthCodedString(); case Types.GEOMETRY: return parser.parseGeometryValue(); + case Types.JSON: + return JSON.parse(parser.parseLengthCodedString()); default: return parser.parseLengthCodedString(); } diff --git a/test/integration/connection/test-change-user-charset.js b/test/integration/connection/test-change-user-charset.js new file mode 100644 index 000000000..9e3e0219f --- /dev/null +++ b/test/integration/connection/test-change-user-charset.js @@ -0,0 +1,18 @@ +var assert = require('assert'); +var common = require('../../common'); + +common.getTestConnection(function (err, connection) { + assert.ifError(err); + + // should change charset + connection.changeUser({charset:'KOI8R_GENERAL_CI'}, function (err) { + assert.ifError(err); + + connection.query('SHOW VARIABLES LIKE \'character_set_client\'', function (err, result) { + assert.ifError(err); + assert.strictEqual(result[0]['Value'], 'koi8r'); + + connection.destroy(); + }); + }); +}); diff --git a/test/integration/connection/test-format.js b/test/integration/connection/test-format.js new file mode 100644 index 000000000..27ae171a7 --- /dev/null +++ b/test/integration/connection/test-format.js @@ -0,0 +1,14 @@ +var path = require('path'); +var assert = require('assert'); +var common = require('../../common'); +var lib = require(path.resolve(common.lib, '../index')); + +assert.equal( + lib.format('SELECT * FROM ?? WHERE ?? = ?', [ 'table', 'property', 123 ]), + 'SELECT * FROM `table` WHERE `property` = 123' +); + +assert.equal( + lib.format('INSERT INTO ?? SET ?', [ 'table', { property: 123 } ]), + 'INSERT INTO `table` SET `property` = 123' +); diff --git a/test/integration/connection/test-query.js b/test/integration/connection/test-query.js index 42ddba4d7..2d5aa4cd7 100644 --- a/test/integration/connection/test-query.js +++ b/test/integration/connection/test-query.js @@ -8,6 +8,13 @@ common.getTestConnection(function (err, connection) { assert.ifError(err); assert.deepEqual(rows, [{1: 1}]); assert.equal(fields[0].name, '1'); - connection.end(assert.ifError); + + // this is a coverage test, it shuold perform exactly as the previous one + connection.query({ sql: 'SELECT ?' }, [ 1 ], function (err, rows, fields) { + assert.ifError(err); + assert.deepEqual(rows, [{1: 1}]); + assert.equal(fields[0].name, '1'); + connection.end(assert.ifError); + }); }); }); diff --git a/test/integration/connection/test-type-casting.js b/test/integration/connection/test-type-casting.js index 8e53761ff..1ceb6bf20 100644 --- a/test/integration/connection/test-type-casting.js +++ b/test/integration/connection/test-type-casting.js @@ -53,7 +53,8 @@ var tests = [ {type: 'multipoint', insertRaw: "GeomFromText('MULTIPOINT(0 0, 20 20, 60 60)')", expect: [{x:0, y:0}, {x:20, y:20}, {x:60, y:60}], deep: true}, {type: 'multilinestring', insertRaw: "GeomFromText('MULTILINESTRING((10 10, 20 20), (15 15, 30 15))')", expect: [[{x:10,y:10},{x:20,y:20}],[{x:15,y:15},{x:30,y:15}]], deep: true}, {type: 'multipolygon', insertRaw: "GeomFromText('MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))')", expect: [[[{x:0,y:0},{x:10,y:0},{x:10,y:10},{x:0,y:10},{x:0,y:0}]],[[{x:5,y:5},{x:7,y:5},{x:7,y:7},{x:5,y:7},{x:5,y:5}]]], deep: true}, - {type: 'geometrycollection', insertRaw: "GeomFromText('GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))')", expect: [{x:10,y:10},{x:30,y:30},[{x:15,y:15},{x:20,y:20}]], deep: true} + {type: 'geometrycollection', insertRaw: "GeomFromText('GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))')", expect: [{x:10,y:10},{x:30,y:30},[{x:15,y:15},{x:20,y:20}]], deep: true}, + {type: 'json', insert: { name: "mysql", data: [{ id: 5}, { id: 6}]}} ]; var table = 'type_casting'; diff --git a/test/integration/connection/test-types.js b/test/integration/connection/test-types.js new file mode 100644 index 000000000..a9d97a7ab --- /dev/null +++ b/test/integration/connection/test-types.js @@ -0,0 +1,11 @@ +var path = require('path'); +var assert = require('assert'); +var common = require('../../common'); +var lib = require(path.resolve(common.lib, '../index')); +var types = require(path.resolve(common.lib, 'protocol/constants/types')); + +assert.equal(typeof lib.Types, "object"); + +for (var k in types) { + assert.equal(lib.Types[k], types[k]); +} diff --git a/test/unit/connection/test-change-user.js b/test/unit/connection/test-change-user.js index fb38fe8bc..dfe59c78a 100644 --- a/test/unit/connection/test-change-user.js +++ b/test/unit/connection/test-change-user.js @@ -21,8 +21,18 @@ server.listen(common.fakeServerPort, function(err) { assert.ifError(err); assert.strictEqual(result[0]['CURRENT_USER()'], 'user_2@localhost'); - connection.destroy(); - server.destroy(); + // should keep current user + connection.changeUser(function (err) { + assert.ifError(err); + + connection.query('SELECT CURRENT_USER()', function (err, result) { + assert.ifError(err); + assert.strictEqual(result[0]['CURRENT_USER()'], 'user_2@localhost'); + + connection.destroy(); + server.destroy(); + }); + }); }); }); });