Sub Process_Globals
Dim db As SQL
End Sub
Sub AppStart (Args() As String)
' Check and Create database for testing
If File.Exists(File.DirApp,"/database.db") = False Then
db.InitializeSQLite(File.DirApp, "/database.db", True)
db.ExecNonQuery("CREATE TABLE items(timestamp TEXT, NumberOfDays TEXT)")
db.ExecNonQuery("INSERT INTO `items`(`timestamp`,`NumberOfDays`) VALUES ('1547536832454','100')")
db.ExecNonQuery("INSERT INTO `items`(`timestamp`,`NumberOfDays`) VALUES ('1547538059332','100')")
Else
db.InitializeSQLite(File.DirApp, "/database.db", False)
End If
'begin checking
Check
StartMessageLoop
End Sub
Sub Check
Log("Checking...")
Dim RS As ResultSet = db.ExecQuery("SELECT * FROM `items`")
' Loop though all records..
Do While RS.NextRow
If DateTime.GetHour(RS.GetString("timestamp")) = DateTime.GetHour(DateTime.Now) And DateTime.GetMinute(RS.GetString("timestamp")) = DateTime.GetMinute(DateTime.Now) Then
Log("Process item..")
' hour and minute is the same (so it must be the next day)
' Update Database, minus 1 from NumberDays: RS.GetString("NumberOfDays")
End If
Loop
RS.Close
Log("Checking.. Done!")
' Run this sub again in 60 seconds (since minute would of changed)
Sleep(60 * 1000)
Check
End Sub