Android Question MYSQL Search and Update Data

Sapta

Member
Licensed User
Longtime User
Dear all,
I have a question about the search and update the data in mysql by this thread. How do I do that?

Suppose I have a logic:
Searching for data by ID, if found then in the update, if not found then insert.

Is it okay like this, calling ExecuteRemoteQuery repetitive after JobDone?

EXAMPLE
B4X:
Sub btnSimpan_Click
    'Ambil variabel
    Dim vUsername, vNoAgenda, vLongitude, vLatitude, vStatusSurvey As String
    ExecuteRemoteQuery("IF EXISTS(SELECT no_agenda FROM tb_survey WHERE no_agenda = '" & vNoAgenda & "')", SURVEY_INSERT)
End Sub

Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString(SESSION_IP_PHP_SERVER, Query)
End Sub

Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
        Dim res As String
        res = Job.GetString
        Dim parser As JSONParser
        Dim id1, id2 As String
        parser.Initialize(res)
        Select Job.JobName
            Case SURVEY_INSERT
                .....
                id1=m.Get("pid")
ExecuteRemoteQuery("IF EXISTS(SELECT pid FROM tb_survey WHERE pid= '" & id1 & "')", DATA_PEMOHON1)
             
            Case DATA_PEMOHON1
                id2=m.Get("pid")
ExecuteRemoteQuery("IF EXISTS(SELECT no_agenda FROM tb_survey WHERE pid= '" & id2 & "')", DATA_PEMOHON2)
                .....
            Case DATA_PEMOHON2
                .....
        End Select
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Thankyou
 
Top