Android Question help with sqlite code

moster67

Expert
Licensed User
Longtime User
I am not very proficient with databases so I thought I would ask for your help with some code related to SQLite. I could have posted this in the B4j section as well but I thought it was easier here.

It is related to the B4xPushServer and my table-structure (with pseudo-values) is as follows:
B4X:
token = E6XXXXXXXXXXXXXXXXXXX
type = 1
updated_time = 1447672514961
freqpref = 180
This is the code I modified from the B4xPushServer:

B4X:
Dim rows As List = DBUtils.ExecuteMemoryTable(Main.db, _
        "SELECT * FROM tokens WHERE updated_time > ?", _
        Array As String (DateTime.Now + (freqpref*1000)), 0)

In the quoted code, 'freqpref' will not work of course. Instead I need to read the value of 'freqpref' from the DB. Like this:

B4X:
Dim rows As List = DBUtils.ExecuteMemoryTable(Main.db, _
        "SELECT * FROM tokens WHERE updated_time > ?", _
        Array As String (DateTime.Now + (180*1000)), 0)

Can someone help with this code?
 

LucaMs

Expert
Licensed User
Longtime User
Probably you cannot use DBUtils in this case.

You should use the "classic" command:
B4X:
Dim Query As String = "SELECT * FROM tokens WHERE updated_time > (" & DateTime.Now " & " + ( freqpref * 1000)) "
Dim Cur As Cursor = Main.db.Exec...
If Cur...
For r = 0 to Cur.RowCount - 1
    Cur.Position = r
    ...
Next
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thank you Luca. However, my logic in my previous query was completely wrong so I had to re-write it anyway and this time it works.
 
Upvote 0
Top