Comparing version 0.1.2 to 0.2.0
@@ -13,3 +13,2 @@ var EventEmitter = require('events').EventEmitter; | ||
if (!this.next) { | ||
connection._cmdBytesReceived = 0; | ||
this.next = this.start; | ||
@@ -16,0 +15,0 @@ } |
@@ -15,2 +15,6 @@ var Command = require('./command'); | ||
this.resultFields = []; | ||
this.resultFieldCount = 0; | ||
this.insertId = 0; | ||
this.parameters = parameters; | ||
@@ -23,15 +27,21 @@ this.rows = []; | ||
Execute.prototype.start = function(packet, connection) { | ||
var id = connection.statements[this.sql]; | ||
var id = connection.statements[this.query]; | ||
if (!id) { // prepare first | ||
connection.writePacket(new Packets.PrepareStatement(this.query).toPacket(1)); | ||
console.log('preparing ' + this.query); | ||
connection.writePacket(new Packets.PrepareStatement(this.query).toPacket(1)); | ||
} else { | ||
this.id = id; | ||
//console.log('executing cached! ID=' + this.id); | ||
return this.doExecute(connection); | ||
} | ||
return Execute.prototype.resultsetHeader; | ||
return Execute.prototype.prepareHeader; | ||
}; | ||
Execute.prototype.resultsetHeader = function(packet) { | ||
Execute.prototype.prepareHeader = function(packet, connection) { | ||
var header = new Packets.PreparedStatementHeader(packet); | ||
this.fieldCount = header.fieldCount; | ||
this.parameterCount = header.parameterCount; | ||
this.id = header.id; | ||
console.log('saving prepared statement:' + this.id); | ||
connection.statements[this.query] = this.id; | ||
if (this.parameterCount > 0) | ||
@@ -42,3 +52,3 @@ return Execute.prototype.readParameter; | ||
else | ||
return execute.prototype.parametersEOF; | ||
return this.doExecute(connection); | ||
}; | ||
@@ -82,9 +92,63 @@ | ||
{ | ||
console.log('TODO: implement COM_EXECUTE. STMT id =' + this.id); | ||
this.onResult(''); | ||
var executePacket = new Packets.Execute(this.id, this.parameters); | ||
connection.writePacket(executePacket.toPacket(1)); | ||
return Execute.prototype.resultesetHeader; | ||
}; | ||
Execute.prototype.resultesetHeader = function(packet) { | ||
var header = new Packets.ResultSetHeader(packet); | ||
this.resultFieldCount = header.fieldCount; | ||
this.insertId = header.insertId; | ||
if (this.resultFieldCount === 0) { | ||
if (this.onResult) | ||
this.onResult(null, [], []); | ||
return null; | ||
} | ||
return Execute.prototype.readResultField; | ||
}; | ||
Execute.prototype.readResultField = function(packet) { | ||
var def = new Packets.ColumnDefinition(packet); | ||
this.resultFields.push(def); | ||
if (this.resultFields.length == this.resultFieldCount) { | ||
return Execute.prototype.resultFieldsEOF; | ||
} | ||
return Execute.prototype.readResultField; | ||
}; | ||
Execute.prototype.resultFieldsEOF = function(packet) { | ||
// check EOF | ||
if (!packet.isEOF()) | ||
throw "Expected EOF packet"; | ||
return Execute.prototype.row; | ||
}; | ||
Execute.prototype.row = function(packet) | ||
{ | ||
console.log('Execute:row', packet); | ||
// TODO: refactor to share code with Query::row | ||
if (packet.isEOF()) { | ||
if (this.onResult) | ||
this.onResult(null, this.rows, this.fields); | ||
return null; | ||
} | ||
var row = Packets.BinaryRow.fromPacket(this.fields, packet); | ||
// TODO: here we'll have dynamically pre-compiled and cached row parser | ||
if (true) // TODO: think of API to store raw copulns array (most probably connection options flags) | ||
{ | ||
var r = {}; | ||
for (var i = 0; i < row.columns.length; ++i) | ||
{ | ||
var name = this.resultFields[i].name; | ||
r[name] = row.columns[i]; | ||
} | ||
if (this.onResult) | ||
this.rows.push(r); | ||
else | ||
this.emit('result', r); | ||
} else { | ||
if (this.onResult) | ||
this.rows.push(row.columns); | ||
else | ||
this.emit('result', row.columns); | ||
} | ||
return Execute.prototype.row; | ||
@@ -91,0 +155,0 @@ }; |
@@ -52,7 +52,2 @@ var Command = require('./command'); | ||
function Row(columns) { | ||
this.id = columns[0]; | ||
this.name = columns[1]; | ||
} | ||
Query.prototype.row = function(packet) | ||
@@ -66,2 +61,3 @@ { | ||
var row = Packets.TextRow.fromPacket(packet); | ||
// TODO: here we'll have dynamically pre-compiled and cached row parser | ||
@@ -68,0 +64,0 @@ if (true) // TODO: think of API to store raw copulns array (most probably connection options flags) |
@@ -1,4 +0,4 @@ | ||
"handshake handshake_response query resultset_header column_definition text_row prepare_statement prepared_statement_header".split(' ').forEach(function(name) { | ||
"handshake handshake_response query resultset_header column_definition text_row binary_row prepare_statement prepared_statement_header execute".split(' ').forEach(function(name) { | ||
var ctor = require('./' + name); | ||
module.exports[ctor.name] = ctor; | ||
}); |
@@ -24,2 +24,6 @@ //var BigNumber = require("bignumber.js"); | ||
Packet.prototype.dump = function() { | ||
console.log([this.buffer.asciiSlice(this.start, this.end)], this.buffer.slice(this.start, this.end), this.length(), this.sequenceId); | ||
}; | ||
Packet.prototype.haveMoreData = function() { | ||
@@ -68,3 +72,2 @@ return this.end > this.offset; | ||
console.trace(); | ||
debugger; | ||
//throw "Implement 8bytes BigNumber"; | ||
@@ -97,8 +100,29 @@ } | ||
this.offset = end + 1; | ||
return this.buffer.toString('utf8', start, end); // TODO: encoding? | ||
return this.buffer.utf8Slice(start, end); | ||
}; | ||
// TODO reuse? | ||
Packet.prototype.readString = function(len) { | ||
this.offset += len; | ||
return this.buffer.utf8Slice(this.offset - len, this.offset); | ||
}; | ||
// TODO: base? sign? parseFloat? | ||
Packet.prototype.parseInt = function(len) { | ||
var result = 0; | ||
var end = this.offset + len; | ||
while(this.offset < end) { | ||
result *= 10; | ||
result += this.buffer[this.offset] - 48; | ||
this.offset++; | ||
} | ||
return result; | ||
}; | ||
Packet.prototype.parseLengthCodedInt = function() { | ||
return this.parseInt(this.readLengthCodedNumber()); | ||
} | ||
Packet.prototype.isError = function() { | ||
// TODO: will be changed to buffer[4] | ||
return this.buffer[0] == 0xff; | ||
return this.buffer[this.offset] == 0xff; | ||
}; | ||
@@ -105,0 +129,0 @@ |
@@ -7,4 +7,12 @@ //var constants = require('../constants'); | ||
this.fieldCount = packet.readLengthCodedNumber(); | ||
// is this correct? | ||
if (packet.haveMoreData()) | ||
this.insertId = packet.readLengthCodedNumber(); | ||
// snippet from mysql-native: | ||
// res.affected_rows = this.lcnum(); | ||
// res.insert_id = this.lcnum(); | ||
// res.server_status = this.num(2); | ||
// res.warning_count = this.num(2); | ||
// TODO: extra | ||
@@ -11,0 +19,0 @@ } |
{ | ||
"name": "mysql2", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "fast mysql driver", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,4 +0,4 @@ | ||
[![Build Status](https://secure.travis-ci.org/sidorares/node-mysql2.png)](http://travis-ci.org/sidorares/node-mysql2) | ||
[![Build Status](https://secure.travis-ci.org/sidorares/node-mysql2.png)](http://travis-ci.org/sidorares/node-mysql2) [![](https://badge.fury.io/js/mysql2.png)](https://npmjs.org/package/mysql2) [![](https://gemnasium.com/sidorares/node-mysql2.png)](https://gemnasium.com/npms/mysql2) | ||
Work in progress. | ||
Aims to be faster drop-in replacement driver for https://github.com/felixge/node-mysql |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42550
38
1223