Dim oSQL As SQL
oSQL.Initialize(DBCREAR.DBFileDir, DBCREAR.DBFileName, False)
If oSQL.IsInitialized Then
' For every record in the file
For i=0 To lsFic.Size-1
Try
' Load fields into array
Dim arr_ValReg(iNumCampTabla) As String
arr_ValReg = lsFic.Get(i)
' Load key values
Dim arr_ValClave(iNumCampClave) As String
For j=0 To iNumCampClave-1
arr_ValClave(j) = arr_ValReg(j)
Next
' Check if the record exists
Dim c As Cursor
c = oSQL.ExecQuery2(sQuery.ToString, arr_ValClave)
If c.RowCount > 0 Then
' Set the position
c.Position = 0
' Capture ID
Dim iIdLinea As Int
iIdLinea = c.GetInt("ID")
' Generate field list for the update
Dim lsCampos As List
lsCampos.Initialize
For k=0 To mCamp.Size-1
lsCampos.Add(mCamp.GetKeyAt(k))
Next
' Close cursor
c.Close
' Generate the update query
Dim sUpdate As String
sUpdate = fsUpdateQuery2(NomTabla,iIdLinea,lsCampos)
' Update record
oSQL.ExecNonQuery2(sUpdate,arr_ValReg)
Log(NomTabla & " : record updated")
Else
c.Close
' Inser record
Dim sInsert As String
sInsert = fsInsertQuery(NomTabla,iNumCampTabla)
oSQL.ExecNonQuery2(sInsert,arr_ValReg)
Log(NomTabla & " : record insert")
End If
Catch
Log(NomTabla & " : couldn't update")
End Try
DoEvents
Next
oSQL.Close
End If