Android Question Problem saving data quickly in SqLite

carlos7000

Active Member
Licensed User
Hi all.

I'm trying to save some of the data I get from the gps in a database.

With the following code I have no problems.

B4X:
Query = "INSERT INTO `GpsData`(`Id`,`UnixTime`,`Lat`,`Lon`,`Speed`,`Bearing`) VALUES (NULL,'" & UnixTime & "','" & Lat & "','" & Lon & "','" & Speed & "','" & Bearing & "');"
Sql1.ExecNonQuery(Query)
Unfortunately the code runs very slow. On average it takes 1 second to execute.
Looking for ways to improve performance I wrote this new code:

B4X:
Sql1.BeginTransaction
Sql1.ExecNonQuery2("INSERT INTO GpsData VALUES(NULL,?,?,?,?,?)", Array As String(UnixTime, Lat, Lon, Speed, Bearing))   
Sql1.EndTransaction
The code runs quickly. On average, the execution time is 50 thousandths of a second, but when reviewing the database, there is no data.

Neither on the phone nor in the log, there is a message of any error.

What could be the problem?
 

carlos7000

Active Member
Licensed User
doing so?

B4X:
Sql1.BeginTransaction
Sql1.ExecNonQuery2("INSERT INTO GpsData VALUES(NULL,?,?,?,?,?)", Array As String(UnixTime, Lat, Lon, Speed, Bearing))   
Sql1.TransactionSuccessful 
Sql1.EndTransaction
 

carlos7000

Active Member
Licensed User
Yes. If you use a transaction but don't mark it as successful, the data is ignored.
I can not believe I forgot that line.

The speed improved to 700 miles per second, but it is still very slow.

Very thanks.
 

Erel

Administrator
Staff member
Licensed User
Sounds like you are doing something wrong. Post all the relevant code.
 
Top