Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
If File.Exists(File.DirDefaultExternal,"l4pro.sql") = False Then
File.Copy(File.DirAssets,"l4pro.sql",File.DirDefaultExternal,"l4pro.sql")
End If
If SQLVariables.IsInitialized = False Then
SQLVariables.Initialize(File.DirDefaultExternal, "l4pro.sql", False)
End If
'AND HERE I'D LIKE TO CHECK IS THE COLUMN EXISTS.
If the SQLVariables.column("Col10") Not exists Then "ALTER TABLE SQLVariables ADD COLUMN Col10 VARCHAR(100)"
End Sub
Dim SQLVariables As SQL 'in Process_Globals
Dim Cursor1 As Cursor 'in Globals
If File.Exists(File.DirDefaultExternal,"l4pro.sql") = False Then
File.Copy(File.DirAssets,"l4pro.sql",File.DirDefaultExternal,"l4pro.sql")
End If
If SQLVariables.IsInitialized = False Then
SQLVariables.Initialize(File.DirDefaultExternal, "l4pro.sql", False)
End If
Dim MyTable As String = "names" 'Put your table name here
Dim txt As String
txt="SELECT * FROM " & MyTable & " LIMIT 1"
Cursor1=SQLVariables.ExecQuery(txt)
Cursor1.Position=0
Dim cols As Int = Cursor1.ColumnCount
Dim MyColName(cols) As String
Dim NewColumn As String = "Col10"
Dim Flag As Boolean =False
For i=0 To Cursor1.ColumnCount-1
MyColName(i)=Cursor1.GetColumnName(i)
If MyColName(i)= NewColumn Then
Msgbox("Column already exists. ","")
Flag=True
Exit
End If
Next
If Flag=False Then
txt="ALTER TABLE " & MyTable & " ADD COLUMN " & NewColumn & " VARCHAR(100)"
SQLVariables.ExecNonQuery(txt)
Msgbox(NewColumn & " was added to the table","")
End If
Try
' Add new columns to the database if they don't already exist
TMM.gsqlMB.ExecNonQuery("ALTER TABLE [PrimaryGroups] ADD [SortField] VarChar(50) default '';")
Catch
If LastException.Message.IndexOf("duplicate column") = -1 Then
' Not a duplicate field problem
sReturnMessage = "Problem creating Sort & Origin Fields: " & LastException.Message
Else
sReturnMessage = "FYI - Duplicate Column(s) found"
End If
End Try