Sub FixFelderCSV(cDB As String) ' cDB ist the name of the table in the DB.
Dim cur As Cursor
Dim DBFields As List
Dim x, nMax As Int
Dim sSQL As StringBuilder
Dim sCMD, sFeld As String
Try
cur = Main.SQL1.ExecQuery( "SELECT * FROM " & cDB & " LIMIT 1" )
DBFields.Initialize
nMax = cur.ColumnCount-1
' read all the fieldnames in LowerCase
For x = 0 To nMax
sFeld = cur.GetColumnName(x).Trim.ToLowerCase
DBFields.Add( sFeld )
Next
For x = 0 To nFieldCount-1 ' CSV fieldnames
sFeld = sHeader(x).Trim.ToLowerCase
If DBFields.IndexOf( sFeld ) = -1 Then
sSQL.Initialize
sSQL.Append( "ALTER TABLE ")
sSQL.Append( cDB )
sSQL.Append( " ADD COLUMN ")
sSQL.Append( sFeld )
sSQL.Append( " TEXT DEFAULT '' ;" )
Log ("New field" & cDB & " " & sFeld )
sCMD = sSQL.ToString
Log ("WRITE " & sCMD )
Try
Main.SQL1.ExecNonQuery( sCMD )
Log( "OK ! " & sCMD )
Catch
Log( "Fehler ! " & sCMD )
Log( LastException.Message )
Msgbox("Error '" & sFeld & "' not in LG !","Structure error")
ExitApplication
End Try
End If
Next
cur.close
Catch
Log( "Error CSV header " )
Log( LastException.Message )
Msgbox("Error CSV header ","Structure error")
ExitApplication
End Try
End Sub