SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query Data Type Problem

    Well this problem has been bugging me for days.

    I have a mysql table with some of these fields:

    money | bigint | 40 | Default: 0 | unsigned

    Now the problem I am having is that my script is somehow maxing out the value in the money field with simple mysql addition and subtraction. This only happens when 2 people reference a script that updates 1 persons money.

    One person goes to the bank.php and deposits say 200,000. At the same time another user goes to battle.php and attacks the first person. Because of the lag in the scripts all the sudden the first person has 1.8446744069415E+19 for there money. As you know this is exactly the maximum integer for a bigint field that is unsigned.

    Now my queries looking something like this when I print it out when there executing.

    Update table set money=money+$deposit where playerid=$id
    Update table set money=money-$battleloss where playerid=$id

    They are simple math operations like that. I tried every combination of the query I could and they all worked fine without making the value to the max. I tried money=money+-100, money=money+100, money=money--100. I tried every form that I could and none of them will work.

    What would cause a mysql query to set a field value to the maximum that it could be? In only seems to happen when 2 separate queries in 2 separate queries run at the same time updating the same field.

    Im really struggling on fixing this bug that generates, who knows what that number is called.

    Thank you for any help you can provide.

  2. #2
    The Omnipresent [ArcanE]'s Avatar
    Join Date
    Mar 2005
    Location
    Belgium
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good question, maybe it'd help you posted the relevant part of your code?
    Webdevelopment : Skyrocket Concepts Inventis Web Architects
    Ain't got time for the future or the past.
    Live for the moment, make it last.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Xiosen View Post
    What would cause a mysql query to set a field value to the maximum that it could be?
    setting it to a small negative number
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by [ArcanE] View Post
    Good question, maybe it'd help you posted the relevant part of your code?
    The code for it is pretty long. I could however if you think it would help.

    Quote Originally Posted by r937 View Post
    setting it to a small negative number
    Can you give me an example of a query so I know what to look for? Ive tried through phpmyadmin subtracting like 400 from 300 so it would enter a negative but it always ends up 0 no matter what I try.

    Ive tried the following to reduplicate it: money=money+-100, money=money+100, money=money--100, money=money-100. All of these queries ive tried when the value was below 100 and above 100.

    Do you know an example that would cause this, and an example of what it should be instead?

    Thank you both for your help!

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Xiosen View Post
    Can you give me an example of a query so I know what to look for? Ive tried through phpmyadmin subtracting like 400 from 300 so it would enter a negative but it always ends up 0 no matter what I try.
    i've just tried it and i cannot get it to go negative (i.e. large positive) either, it just stays at 0

    sorry

    don't know what's causing your problem
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone else have any ides?

    It seems that the only time this occurs is when the game lags and the 2 scripts are running at the same time trying to do 2 different mathmatrical operations like +100 and -50 that it bugs out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •