Skip to content

Commit

Permalink
pass query options to query command
Browse files Browse the repository at this point in the history
  • Loading branch information
sidorares committed Apr 27, 2014
1 parent 22caf73 commit 120ebc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 6 additions & 4 deletions lib/commands/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ var util = require('util');
var compileParser = require('../compile_text_parser.js');
var ServerStatus = require('../constants/server_status.js');

function Query(sql, callback)
function Query(sql, options, callback)
{
Command.call(this);
this.query = sql;
this.options = options;
this.onResult = callback;
this._fieldCount = 0;
this._rowParser = null;
Expand Down Expand Up @@ -71,8 +72,9 @@ Query.prototype.resultsetHeader = function(packet) {
};

// TODO: move to connection.js ?
function getFieldsKey(fields) {
function getFieldsKey(fields, options) {
var res = '';
res += (typeof options.nestTables) + '/' + options.nestTables + '/' + options.rowsAsHash
for (var i=0; i < fields.length; ++i)
res += '/' + fields[i].name + ':' + fields[i].columnType + ':' + fields[i].flags;
return res;
Expand All @@ -96,10 +98,10 @@ Query.prototype.readField = function(packet, connection) {
if (this._receivedFieldsCount == this._fieldCount) {
var fields = this._fields[this._resultIndex];
this.emit('fields', fields, this._resultIndex);
var parserKey = getFieldsKey(fields);
var parserKey = getFieldsKey(fields, this.options);
this.rowParser = connection.textProtocolParsers[parserKey];
if (!this.rowParser) {
this.rowParser = compileParser(fields);
this.rowParser = compileParser(fields, this.options, connection.config);
//this.rowParser = require('../bench-text-parser');
connection.textProtocolParsers[parserKey] = this.rowParser;
}
Expand Down
20 changes: 9 additions & 11 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ function Connection(opts)

var connection = this;
this.sequenceId = 0;

this.stream.on('error', function(err) {
connection.emit('error', err);
});
});

// big TODO: benchmark if it all worth using 'ondata' and onPacket callbacks directly
// compositing streams would be much more easier.
Expand All @@ -74,9 +74,7 @@ function Connection(opts)
// TODO: measure if we actually get something here
// if yes, re-enable for node 10
//if (this.stream instanceof net.Stream) {
// debugger;
// this.stream.ondata = function(data, start, end) {
// debugger;
// connection.packetParser.execute(data, start, end);
// };
//} else {
Expand All @@ -89,7 +87,7 @@ function Connection(opts)
// we need to set this flag everywhere where we want connaction to close
if (connection._closing)
return;

if (!connection._protocolError) // no particular error message before disconnect
connection._protocolError = 'PROTOCOL_CONNECTION_LOST'
var err = new Error('Connection lost: The server closed the connection.');
Expand Down Expand Up @@ -137,7 +135,7 @@ Connection.prototype.startTLS = function(onSecure) {
var crypto = require('crypto');
var tls = require('tls');
var config = this.config;
var stream = this.stream;
var stream = this.stream;

// special case for Amazon RDS: use http://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem CA cert if ssl option set to "Amazon RDS"
if (config.ssl === 'Amazon RDS') {
Expand All @@ -146,11 +144,11 @@ Connection.prototype.startTLS = function(onSecure) {
fs.readFile(path.resolve(__dirname, '../fixtures/mysql-ssl-ca-cert.pem'), function(err, ca) {
if (err) throw err;
config.ssl = { ca: ca };
after();
after();
});
} else
after();

function after() {
var credentials = crypto.createCredentials({
key: config.ssl.key,
Expand Down Expand Up @@ -321,7 +319,7 @@ Connection.prototype.query = function(sql, values, cb) {
options.values = values;
}
var rawSql = this.format(options.sql, options.values || []);
return this.addCommand(new Commands.Query(rawSql, _domainify(cb)));
return this.addCommand(new Commands.Query(rawSql, options, _domainify(cb)));
};

Connection.prototype.execute = function(sql, values, cb) {
Expand Down Expand Up @@ -401,13 +399,13 @@ Connection.prototype.createBinlogStream = function(opts) {
// TODO: pipe errors as well
})
return stream;
}
}

Connection.prototype.connect = function(cb) {
if (!cb) return;
var connectCalled = 0;

// TODO domainify this callback as well. Note that domain has to be captured
// TODO domainify this callback as well. Note that domain has to be captured
// at the top of function due to nested callback
function callbackOnce(isErrorHandler) {
return function(param) {
Expand Down

0 comments on commit 120ebc3

Please sign in to comment.