Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Dim Timer1 As Timer
Dim Interval As Int = 10
Dim Counter As Int
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
' Start a timer
Timer1.Initialize("Timer1", Interval * 1000)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
Log(" ")
Log("Run a database update query")
Counter = Counter + 1
'AddRecord("Insert #" & Counter)
UpdateID("Updated #" & Counter, 1)
Log("Next run " & DateTime.Time(DateTime.Now + Interval * 1000))
End Sub
'Sub AddRecord(Message As String)
' Dim req As DBRequestManager = CreateRequest
' Dim cmd As DBCommand = CreateCommand("insert_test", Array(Message))
' Wait For (req.ExecuteCommand(cmd, Null)) JobDone(j As HttpJob)
' If j.Success Then
' LogDebug("Success")
' Else
' Log("Error: " & j.ErrorMessage)
' End If
' j.Release
'End Sub
Sub UpdateID(Message As String, ID As Int)
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("update_test", Array(Message, ID))
Wait For (req.ExecuteCommand(cmd, Null)) JobDone(j As HttpJob)
If j.Success Then
LogDebug("Success")
Else
Log("Error: " & j.ErrorMessage)
End If
j.Release
End Sub
Sub CreateRequest As DBRequestManager
Dim req As DBRequestManager
req.Initialize(Me, Main.rdcLink)
Return req
End Sub
Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = Name
If Parameters <> Null Then cmd.Parameters = Parameters
Return cmd
End Sub