Making sure an entry exists in SQLite

N1c0_ds

Active Member
Licensed User
Let's say you try to get information from a line with a unique ID that doesn't exist in SQLite. It creates an error and causes big problems with my application.

Would there be a way to return a nice error message instead?


In context:
Gecko uses a unique ID to get application info from an SQLite database and uses this information to either get an application based on a command and close (command line mode) or display the information and offer options (user-friendly mode). If it creates an error, it can start a chain reaction and cause more problems.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use:
B4X:
Sub App_Start
 cmdID.AddParameter("id")
 cmdID.CommandText = "SELECT count(*) FROM table WHERE col = @id"
 ...
End Sub

Sub IDExists (id)
 cmdID.SetParameter("id",id)
 reader.Value = cmdID.ExecuteReader
 reader.ReadNextRow
 res = reader.GetValue(0) 
 reader.close 
 if res > 0 then return true else return false
End Sub

Usage example: If IDExists("someid") then ...
 
Top