The purpose of this function is to return the SELECT command by using a map field, operator, value pairs for use with the MSMySQL library. As you will note, the values passed to the map are assumed to be strings. When defining the map, you include the operator to choose the values with.
Usage..
Then, you check the record counted and then execute another...
See MSMySQL_InsertHelper for more details.
B4X:
Public Sub MSMySQL_SelectHelper(tblName As String, iMap As Map) As String
' pass a map with field names and field values to
' build a select SQL string for MSMySQL
' assuming all values to insert are string
Dim sb As StringBuilder
Dim fTot As Int
Dim fCnt As Int
Dim colName As String
Dim colValue As String
' find the size of the map
fTot = iMap.size - 1
' start building the sql query
sb.initialize
sb.Append("SELECT * FROM " & tblName & " WHERE ")
For fCnt = 0 To fTot
' get field name
colName = iMap.GetKeyAt(fCnt)
' get field value
colValue = iMap.GetValueAt(fCnt)
sb.append(colName)
sb.append("'")
sb.append(colValue)
sb.append("'")
If fCnt <> fTot Then sb.Append(" AND ")
Next
sb.Append(";")
Return sb.tostring
End Sub
Usage..
B4X:
Dim wSite As Map
wSite.Initialize
wSite.Put("SiteName = ", txtSiteName.Text)
Dim iQry As String = modMashiane.MSMySQL_SelectHelper("Sites", wSite)
hDB.db.QueryASync(iQry, "checkSite")
Then, you check the record counted and then execute another...
B4X:
Sub MySQL_QueryResult(data As List, meta As Map)
' get records returned
Dim rTot As Int
rTot = meta.Get("RecordCount")
Select Case rTot
Case 1
' tell user that the site exists
modMashiane.Alert(txtSiteName.Text & " Error", "This site has already been added to the server db!")
txtSiteName.RequestFocus
Case Else
' everything is spruce, insert record to database...
See MSMySQL_InsertHelper for more details.