'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
#AdditionalJar: sqlite-jdbc-3.36.0.2
Sub Process_Globals
Private DB As SQL
End Sub
Sub AppStart (Args() As String)
RunTest
StartMessageLoop
End Sub
Sub RunTest
DB.InitializeSQLite(File.DirApp, "test.db", True)
Dim qry As String
qry = $"CREATE TABLE "table1" ("id" INTEGER, "oldcolumn" TEXT, PRIMARY KEY("id" AUTOINCREMENT))"$
DB.AddNonQueryToBatch(qry, Null)
qry = $"INSERT INTO table1 (oldcolumn) SELECT ?"$
DB.AddNonQueryToBatch(qry, Array As String("AAA"))
DB.AddNonQueryToBatch(qry, Array As String("BBB"))
Dim SenderFilter As Object = DB.ExecNonQueryBatch("SQL")
Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
Log("Create: " & Success)
qry = "SELECT id, oldcolumn FROM table1"
Dim res As ResultSet = DB.ExecQuery(qry)
PrintTable(res)
qry = $"ALTER TABLE "table1" RENAME COLUMN "oldcolumn" TO "newcolumn""$
DB.AddNonQueryToBatch(qry, Null)
Dim SenderFilter As Object = DB.ExecNonQueryBatch("SQL")
Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
Log("Alter: " & Success)
qry = "SELECT * FROM table1"
Dim res As ResultSet = DB.ExecQuery(qry)
PrintTable(res)
End Sub
Sub PrintTable (Res As ResultSet)
Dim sb As StringBuilder
sb.Initialize
For i = 0 To Res.ColumnCount - 1
sb.Append(Res.GetColumnName(i)).Append(" | ")
Next
Log(sb.ToString)
Do While Res.NextRow
Dim sb As StringBuilder
sb.Initialize
For i = 0 To Res.ColumnCount - 1
sb.Append(Res.GetString2(i)).Append(" | ")
Next
Log(sb.ToString)
Loop
Res.Close
End Sub