Difference between revisions of "Database.TableIndexes"

From Xojo Documentation

(Sample Code)
(Notes)
 
Line 13: Line 13:
  
 
== Notes ==
 
== Notes ==
 +
A [[DatabaseException]] will be raised if an error occurs.
 +
 
The [[RowSet]] returns one row for each index on the table and it has one field: IndexName As [[String]].
 
The [[RowSet]] returns one row for each index on the table and it has one field: IndexName As [[String]].
  

Latest revision as of 16:09, 12 January 2022

Method

Database.TableIndexes(TableName as String) As RowSet

New in 2019r2

Supported for all project types and targets.

Returns a RowSet containing the list of indexes for the passed TableName. Returns Nil if the table has no indexes or the database source does not support indexes.

Notes

A DatabaseException will be raised if an error occurs.

The RowSet returns one row for each index on the table and it has one field: IndexName As String.

Sample Code

This code displays the indexes for the "Invoices" table (if it exists) in the specified SQLite database:

Var dbFile As FolderItem
dbFile = FolderItem.ShowOpenFileDialog("")

If dbFile <> Nil Then
Var db As New SQLiteDatabase
Try
db.Connect
Var indexRS As RowSet
indexRS = db.TableIndexes("Invoices") // A table with indexes in the SQLite DB
For Each row As DatabaseRow In indexRS
MessageBox("Index: " + row.ColumnAt(0).StringValue)
Next
indexRS.Close
Catch error As NilObjectException
MessageBox("This database has no indexes.")
Catch error As DatabaseException
MessageBox("Could not connect to database. Error: " + error.Message)
End Try
End If