From Xojo Documentation

Revision as of 19:05, 3 September 2020 by THill (talk | contribs) (Text replacement - "{{Deprecated" to "{{DeprecatedItem")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Database.SQLSelect(SelectString as String) As RecordSet

Supported for all project types and targets.

This is an SQL statement that returns a RecordSet. SelectString contains the SQL statement.


Typically only SQL SELECT statements return a RecordSet, but some databases return a RecordSet for SQL commands such as INSERT, UPDATE or stored procedures.

If the SQL does not return data then Nil is returned. Nil is also usually returned if there is an error in the SQL statement, but you should instead check Database.Error to check if an error occurred.

To avoid SQL Injection, be sure to use Prepared SQL Statements.

Sample Code

This code gets the names of the tables in a SQLite database using its built-in 'sqlite_master' table:

Dim dbFile As FolderItem
dbFile = GetOpenFolderItem("") // Choose a SQLite DB

Dim db As New SQLiteDatabase
db.DatabaseFile = dbFile

If db.Connect Then
Dim rs As RecordSet
rs = db.SQLSelect("SELECT * FROM sqlite_master;")

If db.Error Then
MsgBox("Error: " + db.ErrorMessage)
End If

If rs <> Nil Then
While Not rs.EOF
If rs.Field("type").StringValue = "table" Then
MsgBox("Table: " + rs.Field("name").StringValue)
End If
End If
If db.Error Then
MsgBox("Error: " + db.ErrorMessage)
End If
End If