# Android Code SnippetMSMySQL_DeleteHelper

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.

B4X:
``````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
sb.initialize
sb.Append("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)
sb.append(colName)
If bHasQuote = True Then sb.append("'")
sb.append(colValue)
If bHasQuote = True Then sb.append("'")
If fCnt <> fTot Then sb.Append(" AND ")
Next
sb.Append(";")
Return sb.tostring
End Sub``````

Usage...

B4X:
``````ProgressDialogShow("Deleting reservior, please wait...")
Dim dMap As Map
dMap.Initialize
dMap.Put("id = ", rID)
Dim dQry As String = MSMySQL_DeleteHelper("Sites", dMap, False)
hDB.db.ExecuteASync(dQry, "deleteSite")``````

#### Mashiane

##### Expert
Longtime User
B4X:
``````Sub FixOperator(sValue As String) As 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 & " = "
Else
sValue = sValue & " "
End If
Return sValue
End Sub``````

• DonManfred and JakeBullet70

Android Code Snippet [B4X] B4XTable - Delete Row
Replies
2
Views
6K
Android Code Snippet MSMySQL_UpdateHelper
Replies
0
Views
2K
Android Code Snippet MSMySQL_SelectHelper
Replies
2
Views
2K
Android Code Snippet MSMySQL_InsertHelper
Replies
1
Views
2K
Android Tutorial SQL tutorial
Replies
161
Views
257K
{"ft_lang_label":"__label__en","ft_lang_prob":0.52848816,"math_prob":0.9687473,"size":1263,"snap":"2022-27-2022-33","text_gpt3_token_len":347,"char_repetition_ratio":0.123907864,"word_repetition_ratio":0.020304568,"special_character_ratio":0.25178146,"punctuation_ratio":0.15537849,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9815823,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-17T10:11:35Z\",\"WARC-Record-ID\":\"<urn:uuid:0c9fcd58-1cb9-410c-8ec0-3319cea0cf9a>\",\"Content-Length\":\"77198\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f519ba87-ff63-484a-9ae9-8252651c3602>\",\"WARC-Concurrent-To\":\"<urn:uuid:d46c421c-b633-474c-ab16-c869d9e5a993>\",\"WARC-IP-Address\":\"67.227.218.133\",\"WARC-Target-URI\":\"https://www.b4x.com/android/forum/threads/msmysql_deletehelper.57296/\",\"WARC-Payload-Digest\":\"sha1:7UOSMVNZP766RSQVV76DRFG5QF24CSFO\",\"WARC-Block-Digest\":\"sha1:DL64AUF2Q6AJAZPZMO6RIAN5YTOVUIQX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882572898.29_warc_CC-MAIN-20220817092402-20220817122402-00003.warc.gz\"}"}