Friday, June 1, 2007

Table Present?

Two ways to test to see if a table is present:

One

The following code will determine is a table is present and delete it.

TDatabase *db = qry->OpenDatabase();
const String TABLE_NAME = "AC130U_061016_corrected";
TStringList *list = new TStringList;
db->GetTableNames( list );
if ( list->IndexOf(TABLE_NAME)>=0 )
{
String s1 = "DROP TABLE [" + TABLE_NAME + "];";
qry->Execute( s1 );
}

The qry is of type TQuery.

Two

bool HasTable=false;

TTable *testTable = new TTable(NULL);
try
{
testTable->DatabaseName = dbase->DatabaseName;
testTable->TableName = TableName;
HasTable = testTable->Exists;
}
__finally
{
delete testTable;
}


No comments: