iOS Question Problem with ExecuteQuery2

marcick

Well-Known Member
Licensed User
Longtime User
I suppose I'm doing something of wrong but this i the problem:

StoDate is a text field and represent a date in the format "2016-02-01 12:54:00"

If I use this code

B4X:
Dim rs As ResultSet = MySub.SQL_Bls1.ExecQuery("SELECT * FROM records WHERE V_ID = 2587 ORDER BY StoDate DESC LIMIT 1")
    Do While rs.NextRow
        Log(">>> " & rs.GetString("v_id") & " - " & rs.GetString("StoDate"))
    Loop

I obtain the expected result, the most recent record

>>> 2587 - 2016-01-27 08:50:30

If I use this code instead

B4X:
Dim rs As ResultSet=MySub.SQL_Bls1.ExecQuery2("SELECT * FROM records WHERE V_ID = ? ORDER BY ? DESC LIMIT 1", Array("2587", "StoDate"))
    Do While rs.NextRow
        Log("*** " & rs.GetString("v_id") & " - " & rs.GetString("StoDate"))
    Loop

I obtain the oldest record

*** 2587 - 2016-01-07 06:46:59

In other words the "order by" clause is ignored
Where is my fault ?
 

marcick

Well-Known Member
Licensed User
Longtime User
Not really understood.
Do you mean like this ?

B4X:
Dim rs As ResultSet=MySub.SQL_Bls1.ExecQuery2("SELECT * FROM records WHERE V_ID = ? ORDER BY ? DESC LIMIT 1", Array(2587, "StoDate"))
    Do While rs.NextRow
        Log("*** " & rs.GetString("v_id") & " - " & rs.GetString("StoDate"))
    Loop

The result is the same
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Ah ..... yes, now it works

B4X:
Dim rs As ResultSet=MySub.SQL_Bls1.ExecQuery2("SELECT * FROM records WHERE V_ID = ? ORDER BY StoDate DESC LIMIT 1", Array(2587))
    Do While rs.NextRow
        Log("*** " & rs.GetString("v_id") & " - " & rs.GetString("StoDate"))
    Loop

Great Erel
 
Upvote 0
Top