-
Notifications
You must be signed in to change notification settings - Fork 2.5k
bigint insert ids error #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you do an INSERT or UPDATE you must use a string representation of the number.. INSERT INTO tempTable SET BigIntField = '23339090909090909786786768687687' If you try to read from a big int field or from count(), see Issue #373 |
The problem @sirian is having is that there is a CREATE TABLE `t` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`c` VARCHAR(2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=72057594037927935 DEFAULT CHARSET=utf8; connection.query('INSERT INTO `t` SET `c` = ?;', ['a'], function (err, result) {
if (err) throw err;
console.log('New row ID: %s', result.insertId);
}); As far as I can tell, there is no way to work-around this without something being changed in |
Big numbers are converted to connection.query({
sql: "SELECT * FROM " + table,
typeCast: function (field, next) {
if (field.type == 'LONGLONG') {
return field.string();
}
return next();
}
}, function (err, results) {
// ...
}); |
@dresende does the custom typecast even apply to parsing |
AFAIK, type casting doesn't apply when parsing |
I tested it. function typeCastBigInt(field, next) {
if (field.type === 'LONGLONG') {
return field.string();
}
return next();
}
function handleResult(err, result) {
if (err) {
throw err;
}
console.log('New row ID: %s', result.insertId); // needs to be %s since Big Ints have to be represented as string in JS
}
var mysql = require('mysql');
var dbConfig = require('./dbConfig');
dbConfig.database = 'test';
var connection = mysql.createConnection(dbConfig);
connection.connect();
var sql = 'INSERT INTO `t` SET `c` = ' + connection.escape('a') + ';';
connection.query({sql: sql, typeCast: typeCastBigInt}, handleResult);
connection.end();
The row is correctly inserted into the table from above, though. [ t.id = 72057594037927935, t.c= 'a' ] |
hope this bug will be fixed ASAP, don't want to migrate on smth else |
The problem lies in Parser.js#L174. |
We can't use typeCast here. Parser must be able to convert the value to string when exceeds the limit. |
I have a patch using |
Works with my example code. |
@kai-koch how the pull request currently is, you'll usually have a JS Number in |
How would the general behaviour of Big Ints be changed by this? I followed the discussion thru the different issues concerning big ints, when it was decided to have custom typeCast-functions. There should be at least the same behaviour every where a big int is returned. I personally rely on strings on LongLong fields, since no precision is lost. I haven't locked through bignumber.js, but how does it impact performance? (@dougwilson referred to the unedited post. I decided to eloborate my question more in this comment) BTW: My IDE naggs that |
This was fixed since #382 landed in master. Will probably release a new alpha version. |
Fix tests with MySQL 5.7.9
Error happens while node-mysql parses insertid (auto increment bigint field) after row insertion in OkPacket:
Parser.prototype.parseLengthCodedNumber: "parseLengthCodedNumber: JS precision range exceeded number is >= 53 bit ..."
how to fix it?
The text was updated successfully, but these errors were encountered: