Tuesday, July 14, 2009

Tip #47 – Getting a List of Tables on a Connection

There are several ways to list the tables (files) on an Advantage Connection. When connected to a data dictionary you can use system.tables which returns a list of all the tables contained within the database. You can also use regular file operations to get the contents of the data folder. However, your user may not have rights to the directory where the data resides so a file operation may fail.

The AdsConnection object has a method GetTableNames which will return a string array of all the table names available on the current connection. This list will be returned regardless of the permissions that the user has to the directory. In fact it will even work when the user has no access to the folder at all.

When using the GetTableName function on a free table connection you can filter the results based on the file extension. You simply provide a mask of the file types you wish to display. For instance if you only wanted to see the DBFs available on the connection you would provide the "*.dbf" mask ( ex: cnAds.GetTableNames( "*.dbf" ) ). The default is to provide all of the table names for the table type specified in the connection string, ADT is the default table type.

Free Table List

When using GetTableNames on a dictionary connection you can see all of the tables in a linked dictionary by providing a Boolean value ( ex: cnAds.GetTableNames( true );  ). Linked tables will be shown in the following format <LinkName>::<TableName>. Linked tables are not listed by default.

Data Dictionary Tables with Links

1 comment:

Unknown said...

How can I get the names of all free tables associated with a connection inside of Advantage Data Architect?