Hi,
If I use the following code my table gets populated:
If I execute the batch version it does not insert records, but doesn't thrown any errors.
Why would this be, I wonder.
I want to use batch as the queries take a long time to run and I want to be able to interact with the process.
Best regards
Rob
If I use the following code my table gets populated:
Non-Batch Insert:
'============================================================================================
private Sub insertRecsToTempBuffer(recList As List, tblTempMetaDataArg As tblTemp_Meta_t, N5Arg As Int)
Dim n As Int = 1
Dim listN As Int
Dim ArgArray As List
ArgArray.Initialize
listN = recList.Size
Dim qryStr As String
Dim rSet As ResultSet
'test the data set to ensure all records for the five minute time windows will fit in memory
qryStr = _
$"INSERT INTO tblAgg2SecTemp(
julianDateUTC,
jDate,
JdateTime5Min,
dataTicks,
frequency,
Vrms,
P1,
P2,
P3,
ProcessorTemp,
mainBatteryVolts,
Quality,
serverTicksStart,
serverTicksEnd,
N5,
dataTicksString,
JdateTime5MinStr)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"$
For Each row() As String In recList
ArgArray.Clear
ArgArray.Add(row(0))
ArgArray.Add(row(1))
ArgArray.Add(row(2))
ArgArray.Add(row(3))
ArgArray.Add(row(4))
ArgArray.Add(row(5))
ArgArray.Add(row(6))
ArgArray.Add(row(7))
ArgArray.Add(row(8))
ArgArray.Add(row(9))
ArgArray.Add(row(10))
ArgArray.Add(row(11))
ArgArray.Add(row(12))
If n = listN Then
'Add the time to the last record
ArgArray.Add(DateTime.Now) '13
Else
ArgArray.Add(0) '13
End If
ArgArray.Add(N5Arg) '14
ArgArray.Add(DateTime.Date(row(3)) & " " & DateTime.Time(row(3))) '15
ArgArray.Add(jdt.jdDateTimeToDateTimeStr(row(2))) '16
Try
sqlDbAggTemp.BeginTransaction
sqlDbAggTemp.ExecNonQuery2(qryStr, ArgArray)
sqlDbAggTemp.TransactionSuccessful
Log(jdt.jdDateTimeToDateTimeStr(row(0)))
n = n + 1
Catch
Log(LastException)
End Try
Next
qryStr = _
$"SELECT count(rowid) AS noRecsAdded FROM tblAgg2SecTemp"$
rSet = sqlDbAggTemp.ExecQuery(qryStr)
If rSet.NextRow = False Then
tblTempMetaData.errorFlag = True
End If
tblTempMetaData.noRecsInserted = rSet.GetLong("noRecsAdded")
If tblTempMetaDataArg.noRecsInserted <> listN Then
Log("Insert into tblAgg2SecTemp NList = " & listN & " <> " & " No Inserted = " & tblTempMetaData.noRecsInserted)
tblTempMetaData.errorFlag = True
End If
tblTempMetaData.errorFlag = False
End Sub
If I execute the batch version it does not insert records, but doesn't thrown any errors.
Batch Insert:
'============================================================================================
private Sub insertRecsToTempBuffer(recList As List, tblTempMetaDataArg As tblTemp_Meta_t, N5Arg As Int)
Dim n As Int = 1
Dim listN As Int
Dim ArgArray As List
ArgArray.Initialize
listN = recList.Size
Dim qryStr As String
Dim rSet As ResultSet
'test the data set to ensure all records for the five minute time windows will fit in memory
qryStr = _
$"INSERT INTO tblAgg2SecTemp(
julianDateUTC,
jDate,
JdateTime5Min,
dataTicks,
frequency,
Vrms,
P1,
P2,
P3,
ProcessorTemp,
mainBatteryVolts,
Quality,
serverTicksStart,
serverTicksEnd,
N5,
dataTicksString,
JdateTime5MinStr)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"$
For Each row() As String In recList
ArgArray.Clear
ArgArray.Add(row(0))
ArgArray.Add(row(1))
ArgArray.Add(row(2))
ArgArray.Add(row(3))
ArgArray.Add(row(4))
ArgArray.Add(row(5))
ArgArray.Add(row(6))
ArgArray.Add(row(7))
ArgArray.Add(row(8))
ArgArray.Add(row(9))
ArgArray.Add(row(10))
ArgArray.Add(row(11))
ArgArray.Add(row(12))
If n = listN Then
'Add the time to the last record
ArgArray.Add(DateTime.Now) '13
Else
ArgArray.Add(0) '13
End If
ArgArray.Add(N5Arg) '14
ArgArray.Add(DateTime.Date(row(3)) & " " & DateTime.Time(row(3))) '15
ArgArray.Add(jdt.jdDateTimeToDateTimeStr(row(2))) '16
Try
Log(jdt.jdDateTimeToDateTimeStr(row(0)))
sqlDbAggTemp.AddNonQueryToBatch(qryStr, ArgArray)
n = n + 1
Catch
Log(LastException)
End Try
Next
sqlDbAggTemp.ExecNonQueryBatch("sqlDbAggTemp")
Wait for CanContinueInsertRecsToTemp(Success As Boolean)
qryStr = _
$"SELECT count(rowid) AS noRecsAdded FROM tblAgg2SecTemp"$
rSet = sqlDbAggTemp.ExecQuery(qryStr)
If rSet.NextRow = False Then
tblTempMetaData.errorFlag = True
End If
tblTempMetaData.noRecsInserted = rSet.GetLong("noRecsAdded")
If tblTempMetaDataArg.noRecsInserted <> listN Then
Log("Insert into tblAgg2SecTemp NList = " & listN & " <> " & " No Inserted = " & tblTempMetaData.noRecsInserted)
tblTempMetaData.errorFlag = True
End If
tblTempMetaData.errorFlag = False
End Sub
'======================================================================================================
private Sub sqlDbAggTemp_NonQueryComplete(Success As Boolean)
CanContinueInsertRecsToTemp(Success)
End Sub
'======================================================================================================
Sub CanContinueInsertRecsToTemp(Success As Boolean) As ResumableSub
Sleep(0)
#If LOGGING_ON
Log("Can Continue - Main " & DateTime.Date(DateTime.now))
#End If
End Sub
Why would this be, I wonder.
I want to use batch as the queries take a long time to run and I want to be able to interact with the process.
Best regards
Rob