1
votes

Using PowerBuilder 12.5...

My client stored a value in a long and saved it to the database. Eventually the values exceeded the amount possible in a long so it started storing negatives in the database. I know how to recover the original number if it is an integer that overflowed:

ABS(ai_int) + ((32768 - abs(ai_int)) * 2)

but using the same formula with the size of a long in 32768 does not work. Can someone help me get the negative number back to what the user wanted?

1
Where was it overflowed: in the PB client, or in the DBMS? If the latter, which DBMS?Terry

1 Answers

2
votes

Simply assign the Long to an UnsignedLong and it will be the expected value. For a demo create a window and put a MultilineEdit on it then put this in the Open event:

long ll_max = 2147483647
long ll_a, ll_b, ll_c
unsignedlong lul_a, lul_b, lul_c
string ls_out

ll_a = ll_max + 1
ll_b = ll_a + 1
ll_c = ll_b + 1
lul_a = ll_a
lul_b = ll_b
lul_c = ll_c

ls_out = string(ll_max) + "~r~n"
ls_out += string(ll_a) + "~r~n"
ls_out += string(ll_b) + "~r~n"
ls_out += string(ll_c) + "~r~n~r~n"
ls_out += string(ll_max) + "~r~n"
ls_out += string(lul_a) + "~r~n"
ls_out += string(lul_b) + "~r~n"
ls_out += string(lul_c) + "~r~n"

mle_1.text = ls_out

The above produces this output:

2147483647
-2147483648
-2147483647
-2147483646

2147483647
2147483648
2147483649
2147483650