SubName: FieldExists
Author: asales
Description: checks if a column exists in a SQLite database
Usage:
Dependencies: DBUtils (ExecuteMemoryTable)
Tags: DBUtils, Table, Tables, Column, Columns, Field, Fields, Database, DB, SQLite
Author: asales
Description: checks if a column exists in a SQLite database
B4X:
Sub FieldExists(SQL As SQL, TableName As String, TableField As String) As Boolean
Dim result As Boolean
result = False
Dim t As List
t = ExecuteMemoryTable(SQL, "PRAGMA table_info ('" & TableName & "')", Null, 0)
For i = 0 To t.Size - 1
Dim values() As String
values = t.Get(i)
If values(1).ToLowerCase = TableField.ToLowerCase Then ' case insensitive
result = True
Exit
End If
Next
Return result
End Sub
Usage:
B4X:
If DBUtils.FieldExists(SQL1,"MyTable","NAME") = True Then
Log("Field EXISTS!")
Else
Log("Field DO NOT exists.")
End If
Dependencies: DBUtils (ExecuteMemoryTable)
Tags: DBUtils, Table, Tables, Column, Columns, Field, Fields, Database, DB, SQLite
Last edited: