Sub Class_Globals
Private CallBack As Object
Private sqlquery As String
Private database As String
End Sub
Public Sub Initialize(vCallback As Object, vSqlQuery As String, vDatabase As String)
CallBack = vCallback
sqlquery = vSqlQuery
database = vDatabase
End Sub
Public Sub query
Dim j As HttpJob
j.Initialize("", Me)
j.Download2("https://xxxxxxxx.com/mysqlphp.php", Array As String ("query",encode64(sqlquery),"database",encode64(database)))
j.GetRequest.Timeout = 5000
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Try
Dim strResult As String = decode(j.GetString)
If errInHtml(strResult) Then
j.Release
CallSub3(CallBack,"query_finish",False, Null)
End If
Dim parser As JSONParser
parser.Initialize(strResult)
Dim rootlist As List = parser.NextArray
Catch
Log("mysqlphp_trycatch: " & LastException)
j.Release
CallSub3(CallBack,"query_finish",False, Null)
End Try
CallSub3(CallBack,"query_finish",True, rootlist)
Else
CallSub3(CallBack,"query_finish",False, Null)
End If
j.Release
End Sub
Sub errInHtml(txt As String) As Boolean
If txt="" Or txt.Contains("<TITLE>403 Forbidden</TITLE>") Or txt.Contains("<TITLE>404 Not Found</TITLE>") Then
Log("job errInHtml downloading 403 or 404")
Return True
Else
Return False
End If
End Sub
Sub decode(txt As String) As String
Dim strResult As String
Dim cs As CompressedStreams
Dim su As StringUtils
Dim bt() As Byte
Dim bc As ByteConverter
Try
bt = su.DecodeBase64(txt)
bt = cs.DecompressBytes(bt, "zlib")
strResult = bc.StringFromBytes(bt, "UTF8")
Return strResult
Catch
Log(LastException)
Return ""
End Try
End Sub
Sub encode64(txt As String) As String
Dim su As StringUtils
Return su.EncodeBase64(txt.GetBytes("UTF8")) 'data is a bytes array
End Sub