SQL seem to be dropping Precision

nosaj66au

Member
Licensed User
Longtime User
Hi All,
I have been seeing a problem with SQLite. My code is working and creating , reading and write data. However I was logging Lat and Long from the GPS which has return precission to about 10 DP's however when using the variable (loc1.Latitude) in an insert query the table data is truncated (i.e. Lat -38.34411234 become -38.3441) a simlar thing happens with Long. I've tried using column data types of Float , Real , Double Precision, and Decimal(10,5) but the same thing happens.

Any Ideas
Jason:sign0161:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The following code keeps the precision:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      SQL.Initialize(File.DirRootExternal, "1.db", True)
   End If
   SQL.ExecNonQuery("DROP TABLE IF EXISTS table1")
   SQL.ExecNonQuery("CREATE TABLE table1 (col1 REAL)")
   SQL.ExecNonQuery("INSERT INTO table1 VALUES (-38.34411234)")
   Dim c As Cursor
   c = SQL.ExecQuery("SELECT * FROM table1")
   For i = 0 To c.RowCount - 1
      c.Position = i
      Log(c.GetDouble2(0))
   Next
End Sub
 
Upvote 0

nosaj66au

Member
Licensed User
Longtime User
Thanks Erel, you rock. The problem was the read method I used " Log(c.getstring(0))" this was from a previous version of my table, which works but reduces the precision. It didn't flag a conversion error so I didn't see it. However be aware I used your SQL Lite viewer app you wrote, it must also use the getstring or somthing like that, because the value is truncated there too.

Jason
 
Upvote 0
Top