Method
Database_Class.SQLSelect
Warning
This item was deprecated in version 2019r2. Please use Database.SelectSQL as a replacement.
Description
This is an SQL statement that returns a RowSet. SelectString contains the SQL statement.
Notes
Typically only SQL SELECT statements return a RecordSet, but some databases return a RowSet 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 DatabaseException 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 = FolderItem.ShowOpenFileDialog("") ' 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)
Return
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
rs.MoveNext
Wend
rs.Close
End If
db.Close
Else
If db.Error Then
MsgBox("Error: " + db.ErrorMessage)
Return
End If
End If
Compatibility
All project types on all supported operating systems.