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

MyQuery->DatabaseName="SalesDB";
MyQuery->SQL="SELECT * FROM Information.Tables "+
             "WHERE Name="+Engine->QuotedSQLStr("Customer");
MyQuery->Open();
if (RecordCount==1)
   {
   ShowMessage("The Customer table exists");
   }
else
   {
   ShowMessage("The Customer table does not exist");
   };

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

if (MyDatabase->Execute("SELECT * FROM Information.Tables "+
                        "WHERE Name="+Engine->QuotedSQLStr("Customer"))==1)
   {
   ShowMessage("The Customer table exists");
   }
else
   {
   ShowMessage("The Customer table does not exist");
   };
Image