-
Notifications
You must be signed in to change notification settings - Fork 623
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
Double/Real data lost after INSERT and SELECT on Linux #927
Comments
can you clarify if the data is incorrect in the SQLite db (once written), or when read by the driver ? |
I assume the data is incorrect in the SQLite db because when I try |
can you make sure of this assumption, so we know where to look ? I see you insert data with But you also commented:
Can you clarify this part ? |
If you replace the following loop which is in the attachment
by
the problem does not occur. |
The problem also does not occur when I set the last bit of the inserted doubles to zero which means that a tiny amount of precision is potentially lost. |
i have a feeling that the problem may not be in the driver. Can you try to use the |
Using sqlite3 on the Linux system I tried: |
Is there a specific value that consistently reproduce the issue, or is it random? |
The problem is reproducible using the same values. I assume it depends on wether the last bit is important. |
I printed out the critical statement. On both systems it is
which indicates that Double.toString() is not the problem. |
I observed another interesting thing: If I read the same row using Java and sqlite-jdbc on the same System I get |
I further tested the following:
I get: Again all the other Windows Tools show -4.60422358769077 (wrong). Maybe there are some rounding issues? |
Doubles are approximation by design, could be linked to the jvm you use or the hardware, I don't know. |
Sure, but you would assume that the same bit pattern is saved. Btw for someone having the same problem I used the following workaround: Cleaner (but cumbersome) approaches would be:
|
I see you tried a few things and it doesn't seem to be a problem in the driver, but also applies on other tools? Should we be closing this? |
I am not sure because there are different results on Linux and Windows using the same sqlite-jdbc.jar and the reason is not clear (at least for me). I assume other tools have the same problem or similar problems because they use the same binaries. |
If you refer to the binary as the underlying sqlite C library, then the issue should be raised on their tracker. |
Ok, thank you. This could become complicated because sqlite-jdbc is made of Java and underlying libraries and a normal |
According to this discussion it is better to use in general a version which directly inserts a double and avoid a double to text conversion: |
Very good discussion over there. I will be closing this as this is not related to the JDBC driver. |
Describe the bug
After inserting a list of doubles I read them in order to verify if all inserted data is provided by the database in the same way like inserted. In a Linux environment this is not always the case. It seems that the last bit is lost.
To Reproduce
Use the attached Java program like described under Logs.
SqliteInsertReadEqualsTest.txt
Expected behavior
The database should provide inserted values exactly as they were initially.
Logs
Calling the attached program with java -jar SqliteInsertReadEqualsTest.jar 30000 creates the following logs:
Creating sqlite table insertReadTest.sqlite.
Inserting 30000 random doubles.
Checking data. Sequential order.
id: 29246; orig: -4.604223587690774; from Db: -4.6042235876907736 - NOT equal
Checking data. Random order.
id: 29246; orig: -4.604223587690774; from Db: -4.6042235876907736 - NOT equal
Ready.
Java version: 17.0.4
Java vendor: GraalVM Community
OS name: Linux
OS version: 5.4.0-150-generic
CPU architecture: amd64
cpus: 16
free: 205 MB
max: 4002 MB
total: 256 MB
Creating sqlite table insertReadTest.sqlite.
Inserting 30000 random doubles.
Checking data. Sequential order.
No problem.
Checking data. Random order.
No problem.
Ready.
Java version: 17.0.4.1
Java vendor: Eclipse Adoptium
OS name: Windows 10
OS version: 10.0
CPU architecture: amd64
cpus: 4
free: 47 MB
max: 2026 MB
total: 128 MB
Environment (please complete the following information):
Additional context
The probability of the error occurring increases with the number of data added. The number can be passed to the test program in the command line. In the test on my system the error occurred from number 30000.
SqliteInsertReadEqualsTest.txt
The text was updated successfully, but these errors were encountered: