0

I have a SQLite database that contains a table called "players". I can see in DB Browser that the data in the table is correct however when attempting to retrieve the data it seems to be returning a totally different value than what's in the database.

Value in DB: 76561198113034550

Value returned : 152768822

I'm getting the value with the following

qryPlayers.Close;
qryPlayers.SQL.Text := 'SELECT * FROM players';
qryPlayers.Open;

playerID := qryPlayers.FieldByName('steamid').Value; // .AsString returns the same value

Whats causing this and how can I fix it?

1
  • It's difficult to see what might be causing that from what you've posted. Does the value 152768822 appear anywhere in the dB?
    – user16049494
    Jan 23, 2022 at 20:37

1 Answer 1

8

I just checked, what value the 4 lower bytes of 76561198113034550 have... And tadaaa, it is 152768822! So the upper 4 bytes are simply truncated.

Declare playerID as Int64, not Integer or Cardinal since those types only have 4 bytes in memory.
And for retrieving the value from the DB use qryPlayers.FieldByName('steamid').AsLargeInt.

2
  • This was the problem. I thought the Datatype in the DB for steamid was Text but it was Integer instead. I did try your solution however it didnt seem to solve anything. I just changed the datatype to Text in the column. Interesting find though. I wonder why it auto truncates it even though I did retrieve it as a largeint as you suggested. While doing debugging I've noticed regardless what you try to convert it to it's always the wrong value before you even try converting it so it gets trunced while being retrieved. Any idea on how to disable this?
    – Adriaan
    Jan 24, 2022 at 17:21
  • 1
    You should ask a new question. And also add more details: db kind, column data type etc. Jan 24, 2022 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.