I have 6 tables, some have thousands or records and some with a hundred records. I delete their records via code, then immediately import new data to them from a text file as shown in the below excerpt for one of the 6. The transactions take place one table after the other. I am trying to maximize the speed of the SQL transactions. I would like to verify the placement of the keywords: begin, successful and end transaction in the code while dealing with a do loop. It works as I ouline, but sometimes it is fast, and other times it is slow. Erel believes using these keywords in large tables is critical.
B4X:
Dim line As String 'in globals
Dim reader As TextReader
Dim i, j As Int
Dim DBTableName As String
SQL1.BeginTransaction
txt="DELETE FROM " & DBTableName
SQL1.ExecNonQuery(txt)
j=0 'must reset
i=0 'must reset
Do While line <> Null
Try
line = reader.ReadLine
Dim CC() As String 'CC is column content
CC = Regex.Split(",", line) 'field separator is comma. Commas separate the data
SQL1.ExecNonQuery2("INSERT INTO " & DBTableName & " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," _
& "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" _
, Array As Object (CC(0), CC(1), CC(2), CC(3), CC(4), CC(5), CC(6), CC(7), CC(8), CC(9), _
CC(10), CC(11), CC(12), CC(13),CC(14),CC(15),CC(16),CC(17), CC(18), CC(19), CC(20), _
CC(21), CC(22), CC(23), CC(24),CC(25),CC(26),CC(27),CC(28), CC(29), CC(30), CC(31), _
CC(32), CC(33), CC(34), CC(35),CC(36),CC(37),CC(38),CC(39), CC(40), CC(41), CC(42)))
SQL1.TransactionSuccessful
Catch
i = i+1
End Try
DoEvents 'command needed when you have many records to import
j = j + 1
Loop
reader.Close
ProgressDialogHide
SQL1.EndTransaction