### Check if a Record exists

Various ways to check if a record exists in a table.
Using NextRow
'Checks if a record exists in the table for a specific column
'Returns True if exists else false
'Example:
'If DBIsRecord("MyTable", "MyColumn", "MyContent") Then
' Log("Error, Can not add Record as already exists, Please change the content.")
'End If
`Sub DBIsRecord(Table As String, Column As String, SearchString As String) As Boolean
Log("DBIsItem :: Start = " & Table & "/" & Column & "/" & SearchString)
Dim Result As Boolean = False
Dim cur As ResultSet
Try
cur = DBSQL.ExecQuery2("SELECT " & Column & " FROM " & Table & " WHERE " & Column & " = ?",Array As String(SearchString))
If cur.NextRow Then
Result = True
End If
Catch
Log(LastException.message)
End Try
Log("DBIsItem :: End = " & Result)
Return Result
End Sub`
Using Count(*)
'Example checking a database entry
'Checks if a title exists in the database table items field Title
'Parameter Title as string
'Returns True if exists else false
`Sub CheckRecord(Title As String) As Boolean
Dim Result As Boolean = False
Dim rt As Int
Try
rt = gSQL.ExecQuerySingleResult2("SELECT Count(*) FROM items WHERE Title=?",Array As String(Title))
If rt = 1 Then result = True
Catch
Log(LastException.Message)
End Try
Return Result
End Sub`

Changed: , Category: SQLite, File: T6C254M1817.htm, ID: 1817