1. when using this code return = 1628380, table trhinvfa content only 1 row
B4X:
Dim total As Long
total =Sql1.ExecQuerySingleResult("select total from trhinvfa")
2. when using this code return = 1628375
B4X:
Dim curs1 As Cursor
curs1 = Sql1.ExecQuery("select total from trhinvfa")
curs1.Position = 0
For i = 0 To curs1.RowCount - 1
total=curs1.GetLong("total")
Exit
Next
curs1.Close
why using the method one return wrong value (rounding )?
The OP is telling you that the problem is with the first., not the second option. This is what he says: why using the method one return wrong value (rounding )?
Dim sql As SQL
File.Delete(File.DirInternal, "1.db")
sql.Initialize(File.DirInternal, "1.db", True)
sql.ExecNonQuery($"
CREATE TABLE table1 (
total REAL
);
"$)
sql.ExecNonQuery2("INSERT INTO table1 VALUES (?)", Array(1628375))
Log(sql.ExecQuerySingleResult("SELECT total FROM table1"))
If you convert this string to an Int then it will be 1628380.
Changing to TEXT as @Mahares wrote will work, though it is better to switch to ExecQuery2 and get the value with ResultSet.GetInt.
Thanks Erel,Mahares, LucaMS,Hah for your suggestion.
i hope in next update of Sql1 function, it can return real/numeric value (sqlite), not only string couse rounding value.
i am searching 4 hour to trace this error.
There is already a function in SQLite. I gave you the syntax in post #9. It is Printf Apparently, you are not reading the posts carefully. You can leave your data type as REAL and any one of these declarations will work and will not round 1628375 to 1628380 , if you use the Printf mentioned above:
B4X:
Dim total As Int
Dim total As Double
Dim total As Long
Dim total As String