Android Code Snippet MSMySQL_DeleteHelper

Discussion in 'Code Snippets' started by Mashiane, Aug 16, 2015.

Similar threads

B4A Code Snippet MSMySQL_UpdateHelper
B4A Code Snippet MSMySQL_SelectHelper
B4A Code Snippet MSMySQL_InsertHelper
B4A Code Snippet [B4X] GUID
B4A Tutorial Text files
  1. Mashiane

    Mashiane Expert Licensed User

    The purpose of this script is the generation of a Delete sql command for MySQL using the MSMySQL library. To delete, you pass a map containing the field, value pairs to delete from your table.

    Public Sub MSMySQL_DeleteHelper(tblName As String, iMap As Map, bHasQuote As Boolean) As String
    ' pass a map with field names and field values to
        ' build a delete 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
    "DELETE FROM " & tblName & " WHERE ")
    For fCnt = 0 To fTot
    ' get field name
            colName = iMap.GetKeyAt(fCnt)
            colName = FixOperator(colName)
    ' get field value
            colValue = iMap.GetValueAt(fCnt)
    If bHasQuote = True Then sb.append("'")
    If bHasQuote = True Then sb.append("'")
    If fCnt <> fTot Then sb.Append(" AND ")
    Return sb.tostring
    End Sub

    ProgressDialogShow("Deleting reservior, please wait...")
    Dim dMap As Map
    "id = ", rID)
    Dim dQry As String = MSMySQL_DeleteHelper("Sites", dMap, False)
    hibrid0, DonManfred and JakeBullet70 like this.
  2. Mashiane

    Mashiane Expert Licensed User

    Sub FixOperator(sValue As StringAs String
    Dim iOp As Int = 0
        sValue = sValue.Trim
    If sValue.EndsWith("=") = True Then iOp = iOp + 1
    If sValue.EndsWith(">=") = True Then iOp = iOp + 1
    If sValue.EndsWith("<=") = True Then iOp = iOp + 1
    If sValue.EndsWith(">") = True Then iOp = iOp + 1
    If sValue.EndsWith("<") = True Then iOp = iOp + 1
    If sValue.EndsWith("<>") = True Then iOp = iOp + 1
    If iOp = 0 Then
            sValue = sValue & 
    " = "
            sValue = sValue & 
    " "
    End If
    Return sValue
    End Sub
    DonManfred and JakeBullet70 like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice