'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs: "3050" "10000"
#MergeLibraries: True
#End Region
#AdditionalJar : jaybird-full-3.0.2.jar
Sub Process_Globals
Private dbpool As ConnectionPool
Private Sq,ExecQ1,ExecQ2 As SQL
Private RS As ResultSet
Private Tm As Timer
Private Port,Interval As Int
End Sub
Sub AppStart (Args() As String)
If Args.Length > 0 Then
Port = Args(0)
Interval = Args(1)
End If
dbpool.Initialize( "org.firebirdsql.jdbc.FBDriver","jdbc:firebirdsql://localhost:" & Port & "/my_db?charSet=utf-8","user","pass")
Tm.Initialize("TM",Interval)
Tm.Enabled = True
StartMessageLoop
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub TM_Tick
Private Id As Int
Private Val As String
Tm.Enabled = False
Try
Sq = dbpool.GetConnection
ExecQ1 = dbpool.GetConnection
ExecQ2 = dbpool.GetConnection
RS = Sq.ExecQuery("SELECT ID, VAL from snc_log where snc = 0")
Log("OK")
ExecQ1.BeginTransaction
ExecQ2.BeginTransaction
Do While RS.NextRow
Id = RS.GetInt("ID")
Val = RS.GetString("VAL")
Log(Id)
ExecQ1.ExecNonQuery2("update or insert into rcv(id,val) values(?,?)",Array As Object(Id,Val))
ExecQ2.ExecNonQuery("update snc_log set snc = 1 where id = " & Id)
Loop
ExecQ1.TransactionSuccessful
ExecQ2.TransactionSuccessful
RS.Close
Catch
Log(LastException)
End Try
Sq.Close
ExecQ1.Close
ExecQ2.Close
Tm.Enabled = True
End Sub