Mar 22, 2020 Replies: 2 Before we can insert items, we should check, whether the table exists. B4X: Public Sub CheckTableExists(sql As SQL,DBName As String) As Boolean If sql.ExecQuerySingleResult("SELECT count(*) FROM sqlite_master WHERE type='table' AND name ='" & DBName & "'") = 0 Then Return False Else Return True End If End Sub Last edited: Mar 22, 2020 Click to expand...
Before we can insert items, we should check, whether the table exists. B4X: Public Sub CheckTableExists(sql As SQL,DBName As String) As Boolean If sql.ExecQuerySingleResult("SELECT count(*) FROM sqlite_master WHERE type='table' AND name ='" & DBName & "'") = 0 Then Return False Else Return True End If End Sub
Erel B4X founder Staff member Licensed User Longtime User Mar 22, 2020 #2 Thank you for sharing. However: 1. It is really unacceptable to build queries like this. 2. The sub name should be CheckTableExists. 3. Better implementation is available in DBUtils (TableExists). [B4X] DBUtils 2
Thank you for sharing. However: 1. It is really unacceptable to build queries like this. 2. The sub name should be CheckTableExists. 3. Better implementation is available in DBUtils (TableExists). [B4X] DBUtils 2
KMatle Expert Licensed User Longtime User Mar 26, 2020 #3 You should do a db design before you start. So you will know which tables you have. Sometimes it makes sense to create new tables but as a copy of existing ones (e.g. if you have a table for every month or so)
You should do a db design before you start. So you will know which tables you have. Sometimes it makes sense to create new tables but as a copy of existing ones (e.g. if you have a table for every month or so)