- IF you get an exception you do NOT roll back the transaction so it remains open
- ok is NEVER set to false so even if there IS an error to rollback you wont
something like this should work better and NOT leave an open transaction in the case of an error)
Dim bql As String
Dim i as Integer
Dim sql As String
//••••••••••••••••••••• Funzione di salvataggio dati nel DB SQLite esterno •••••••••••••••••••••
bql = "INSERT INTO Contr_Fatti (nome, junior, contratto, data) VALUES ( ?, ?, ?, ?);"
DB.BeginTransaction
var ok as boolean = true
sql = "DELETE FROM Contr_Fatti" // Comando Sql per eliminare tutte le righe salvate nel database Sql
If Contratti_Fatti.ListContrFatt.RowCount > 0 then
Try
DB.ExecuteSQL(sql) //Esegue il comando DELETE
Catch err As DatabaseException
MessageDialog.Show("Error deleting the file from the database: " + err.Message)
OK = false
End Try
if ok = true then
Try
for i = 0 to Contratti_Fatti.ListContrFatt.LastRowIndex
DB.ExecuteSQL( bql, Contratti_Fatti.ListContrFatt.CellTextAt(i, 0), Contratti_Fatti.ListContrFatt.CellTextAt(i, 1), Contratti_Fatti.ListContrFatt.CellTextAt(i, 2),_
Contratti_Fatti.ListContrFatt.CellTextAt(i, 3))
next
Catch err As DatabaseException
MessageDialog.Show("Error deleting the file from the database: " + err.Message)
ok = false
End Try
else
try
DB.ExecuteSQL(sql) //Esegue il comando DELETE
Catch err As DatabaseException
MessageDialog.Show("Error deleting the file from the database: " + err.Message)
ok = false
End Try
end if
if ok then
DB.commit //solo ora salvi tutto
else
DB.rollback
end if