Skip to content

Commit

Permalink
Add some parameter type checking for prepared statements
Browse files Browse the repository at this point in the history
Whenever I use anything besides `Types.DECIMAL` for number type, I get `Error: Incorrect arguments to mysqld_stmt_execute`.

Related to: sidorares#348
  • Loading branch information
kevinmartin authored Jul 28, 2016
1 parent aff0b1c commit 4857e5f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/packets/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,32 @@ Execute.prototype.toPacket = function ()
// if not, previous execution types are used (TODO prooflink)
packet.writeInt8(1); // new-params-bound-flag

// TODO: don't typecast always to sting, use parameters type
// TODO: verify/modify parameter types
for (i = 0; i < this.parameters.length; i++)
{
if (this.parameters[i] !== null) {
packet.writeInt16(Types.VAR_STRING);
switch (typeof this.parameters[i]) {
case 'number':
packet.writeInt16(Types.DECIMAL);
break;

case 'boolean':
this.parameters[i] = +this.parameters[i];
packet.writeInt16(Types.TINY);
break;

case 'object':
if (this.parameters instanceof Date) {
packet.writeInt16(Types.DATETIME);
} else {
// packet.writeInt16(Types.JSON); - Requires MySQL 5.7+
packet.writeInt16(Types.VAR_STRING);
}
break;

default:
packet.writeInt16(Types.VAR_STRING);
}
} else {
packet.writeInt16(Types.NULL);
}
Expand Down

0 comments on commit 4857e5f

Please sign in to comment.