SQL error: BIGINT UNSIGNED value is out of range i

2019-09-14 10:30发布

问题:

I've got a shop system for my game community where people can buy items on our website, and use these things on our game servers, using our own 'green coins' currency. Everything's stored in a SQL database.

However, one specific user has been having trouble buying items. It keeps saying there's a database error when he tries to buy something, but his green coins balance does go down. So I checked the logs, and these errors show up (error format "[time][error location]: [sql error] for query [query]"):

[06-08-2012 23:25:52][1024] Shop: SQL error (buy_item 1): BIGINT UNSIGNED value is out of range in '(admin_source.green_coins.amount_current - 30)' for query UPDATE green_coins SET amount_current = amount_current - 30, last_edit = '2012-08-06 23:25:52' WHERE forum_id = 8760 [06-08-2012 23:25:57][1024] Shop: SQL error (buy_item 1): BIGINT UNSIGNED value is out of range in '(admin_source.green_coins.amount_current - 80)' for query UPDATE green_coins SET amount_current = amount_current - 80, last_edit = '2012-08-06 23:25:57' WHERE forum_id = 8760 [06-08-2012 23:26:01][1024] Shop: SQL error (buy_item 1): BIGINT UNSIGNED value is out of range in '(admin_source.green_coins.amount_current - 1200)' for query UPDATE green_coins SET amount_current = amount_current - 1200, last_edit = '2012-08-06 23:26:00' WHERE forum_id = 8760

Field properties are: forum_id is int(11), amount_current (the green coins balance) is int(11) unsigned, last_edit is datetime

I'd expect this error only to pop up if the amount_current would go below zero, or beyond the upper bound of an unsigned int. However this specific user had a balance of around 11000 (values being subtracted were 5000 at most) and my code already prevents you from buying stuff you can't afford. I found it weird that his balance even went down after the error showed, since the query shouldn't actually execute then. The second weird thing is that, so far, this only happened with this specific user consistently. I can't replicate it on my own account.

Slight note: when I try to view my database using MySQL-Front, the first time I connect to it it shows the error "Error 1548 - Cannot load from mysql.proc. The table is probably corrupted.". However if I click the error away the database seems to be accessible just fine. Could this be related?

标签: sql bigint