TTCatalog Reference
The TTCatalog
class is the top-level class used for programmatically accessing metadata information about tables in a database.
Also see TTCatalog Usage.
Public Methods
This section summarizes then describes the TTCatalog
public methods.
Public Methods Summary
Method | Description |
---|---|
Reads the catalogs in the database for information about tables and indexes and stores this information into |
|
Returns the number of system tables in the database. |
|
Returns the total number of tables (user tables plus system tables) in the database. |
|
Returns the number of user tables in the database. |
|
Returns a constant reference to the |
|
Returns the index in the |
|
Returns a constant reference to the |
fetchCatalogData()
void fetchCatalogData()
This is the only TTCatalog
method that interacts with the database. It reads the catalogs in the database for information about tables and indexes, storing the information into TTCatalog
internal data structures.
Subsequent use of the constructed TTCatalog
object is completely offline after it is constructed. It is no longer connected to the database.
You must call this method before you use any of the TTCatalog
accessor methods.
The following example demonstrates the use of TTCatalog
.
TTConnection conn;
conn.Connect(DSN=TptbmData37);
TTCatalog cat (&conn);
cat.fetchCatalogData();
// TTCatalog cat is no longer connected to the database;
// you can now query it through its read-only methods.
cerr << "There are " << cat.getNumTables() << " tables in this database:" << endl;
for (int i=0; i < cat.getNumTables(); i++)
cerr << cat.getTable(i).getTableOwner() << "."
<< cat.getTable(i).getTableName() << endl;
getNumSysTables()
int getNumSysTables()
Returns the number of system tables in the database. Also see the following methods, getNumTables()
and getNumUserTables()
.
getNumTables()
int getNumTables()
Returns the total number of tables in the database (user plus system tables). Also see the preceding method, getNumSysTables()
, and the following method, getNumUserTables()
.
getNumUserTables()
int getNumUserTables()
Returns the number of user tables in the database. Also see the preceding methods, getNumSysTables()
and getNumTables()
.
getTable()
const TTCatalogTable& getTable(const char* owner, const char* tblname)
const TTCatalogTable& getTable(int tno)
Returns a constant reference to the TTCatalogTable
object for the specified table. Also see getUserTable()
.
For the first signature, this is for the table named tblname
and owned by owner
.
For the second signature, this is for the table corresponding to table number tno
in the system. This is intended to facilitate iteration through all the tables in the system. The order of the tables in this array is arbitrary.
The following relationship is true:
0 <= tno < getNumTables()
Also see TTCatalogTable Usage.
getTableIndex()
int getTableIndex(const char* owner, const char* tblname) const
This method fetches the index in the TTCatalog
object for the specified owner.tblname
object. It returns -2 if owner.tblname
does not exist. It returns -1 if fetchCatalogData()
was not called first.
The example retrieves information about the TTUSER.MYDATA
table from a TTCatalog
object. You can then call methods of TTCatalogTable
, described next, to get information about this table.
TTConnection conn;
conn.Connect(...);
TTCatalog cat (&conn);
cat.fetchCatalogData();
int idx = cat.getTableIndex("TTUSER", "MYDATA");
if (idx < 0) {
cerr << "Table TTUSER.MYDATA does not exist." << endl;
return;
}
TTCatalogTable &table = cat.getTable(idx);
getUserTable()
const TTCatalogTable& getUserTable(int tno)
Returns a constant reference to the TTCatalogTable
object corresponding to user table number tno
in the system. This method is intended to facilitate iteration through all of the user tables in the system. The order of the user tables in this array is arbitrary. Also see getTable()
.
The following relationship is true:
0 <= tno < getNumUserTables()
Note:
There is no equivalent method for system tables.