Icon Querying Database Objects

Database objects are objects that are stored in an ElevateDB database catalog, which is represented by the special system-created Information schema in every ElevateDB database. Querying database objects can be accomplished by using the TEDBQuery component to execute queries against the Information Schema for a given database. This allows you to determine which database objects exist in the database along with specific information about the database objects.

The following example shows how to use a TEDBQuery component containing a SELECT statement to query the Tables Table in the Information Schema in order to see if the "Customer" table exists:

// This example uses a query component that
// has already been created and opened
// called MyQuery

with MyQuery do
   begin
   DatabaseName:='SalesDB';
   SQL:='SELECT * FROM Information.Tables '+
        'WHERE Name='+Engine.QuotedSQLStr('Customer');
   Open;
   if (RecordCount=1) then
      ShowMessage('The Customer table exists')
   else
      ShowMessage('The Customer table does not exist');
   end;

You can also use the TEDBDatabase Execute method as a quicker method to determine if a database object or objects exist. The Execute method returns the number of rows affected or returned by a particular SQL statement, so you can use the return value of an indication of whether any rows exist for the SELECT statement on the Information schema:

// This example uses a database component that
// has already been created and opened
// called MyDatabase

with MyDatabase do
   begin
   if (Execute('SELECT * FROM Information.Tables '+
               'WHERE Name='+Engine.QuotedSQLStr('Customer'))=1) then
      ShowMessage('The Customer table exists')
   else
      ShowMessage('The Customer table does not exist');      
   end;
Image