Previous Topic

Next Topic

Find Table by UID

The overloaded method CTDatabase::FindTable() locates a table in the database given the table UID and retrieves the table name and path. The following example shows how to implement a table open function using the table UID instead of the table name.

// open table using UID
CTTable* OpenByUID(CTDatabase& ADatabase, ULONG uid, CTOPEN_MODE OpenMode)
{
   CTString tblName;
   CTString tblPath;
   CTTable* Retval;

   // locate the table in the database by uid
   if (ADatabase.FindTable(uid, tblName, tblPath))
   {
      Retval = new CTTable(ADatabase);
   
      if (!Retval)
         throw CTException(CTDBRET_NOMEMORY);
   
try
      {
         Retval->Open(tblName, OpenMode);
      }
      catch (CTException& err)
      {
         delete Retval;
         throw;
      }
}
   else
   {
      // table not found
      throw CTException(INOT_ERR);
   }
   return Retval;
}