Android Question DBUtils and ExecuteMap

JMW

Member
Licensed User
Longtime User
I'm looking to understand this:
B4X:
Dim m As Map
    m = DBUtils.ExecuteMap(Starter.sql, "SELECT Project, OriginYear, SurveyType FROM tblProjects WHERE Project = ?", Array As String(spnrProject.SelectedItem, Value))
This results in an error in the log
error in ExecuteMap in dbutils on line:
cur = SQL.ExecQuery2(Query, StringArgs)
java.lang.IllegalArgumentException: Cannot bind argument at index 2 because the index is out of range. The statement has 1 parameters.

But the following works:
B4X:
    Dim m As Map
    Dim strProject As String
    strProject = spnrProject.SelectedItem
    m = DBUtils.ExecuteMap(Starter.sql, "SELECT Project,  OriginYear, SurveyType FROM tblProjects WHERE Project = ?", Array As String(strProject))
Why doesn't the first work?
 

XbNnX_507

Active Member
Licensed User
Longtime User
B4X:
Dim m As Map
    m = DBUtils.ExecuteMap(Starter.sql, "SELECT Project, OriginYear, SurveyType FROM tblProjects WHERE Project = ?", Array As String(spnrProject.SelectedItem, Value))
This results in an error in the log
error in ExecuteMap in dbutils on line:
cur = SQL.ExecQuery2(Query, StringArgs)
java.lang.IllegalArgumentException: Cannot bind argument at index 2 because the index is out of range. The statement has 1 parameters.

It doesnt work because is expecating only one parameter
B4X:
"SELECT Project, OriginYear, SurveyType FROM tblProjects WHERE Project = ?"
you are passing two parameters
B4X:
 array as string ( sprnProject.selectedItem, value)




But the following works:
B4X:
    Dim m As Map
    Dim strProject As String
    strProject = spnrProject.SelectedItem
    m = DBUtils.ExecuteMap(Starter.sql, "SELECT Project,  OriginYear, SurveyType FROM tblProjects WHERE Project = ?", Array As String(strProject))
It works because you passing one parameter. :)
 
Upvote 0
Top