Home > Articles > Programming > General Programming/Other Languages

  • Print
  • + Share This
From the author of

Metadata Representation

You can retrieve information about a database using the TSQLDataset component. To do this, you use the TSQLDataset.SetSchemaInfo() procedure to specify the type of schema information you want. SetSchemaInfo is defined as follows:

procedure SetSchemaInfo( SchemaType: TSchemaType; 
SchemaObjectName, SchemaPattern: string );

The SchemaType parameter specifies the type of schema information that you're requesting. SchemaObjectName holds the name of a table or procedure in the case of a request for parameter, column, or index information. SchemaPattern is an SQL pattern mask used for filtering the result set.

Table 2 is taken from the Delphi online help for the SetSchemaInfo() procedure and describes the types of schema information that you can retrieve.

Table 2 SchemaType Values (from Delphi Online Help)

SchemaType Value

Description

stNoSchema

No schema information. The SQL dataset is populated with the results of its query or stored procedure rather than metadata from the server.

stables

Information about all the data tables on the database server that match the criteria specified by the SQL connection's TableScope property.

stSysTables

Information about all the system tables on the database server. Not all servers use system tables to store metadata. Requesting a list of system tables from a server that doesn't use them results in an empty dataset.

stProcedures

Information about all the stored procedures on the database server.

stColumns

Information about all the columns (fields) in a specified table.

stProcedureParams

Information about all the parameters of a specified stored procedure.

stIndexes

Information about all the indexes defined for a specified table.


We've provided an example of using the SetSchemaInfo() procedure on the CD under the directory SchemaInfo. Listing 1 shows some of the code for this procedure from this example.

Listing 1—Example of TSQLDataset.SetSchemaInfo()

procedure TMainForm.Button1Click(Sender: TObject);
begin
 sqldsSchemaInfo.Close;
 cdsSchemaInfo.Close;

 case RadioGroup1.ItemIndex of
 0: sqldsSchemaInfo.SetSchemaInfo(stSysTables, '', '');
 1: sqldsSchemaInfo.SetSchemaInfo(stTables, '', '');
 2: sqldsSchemaInfo.SetSchemaInfo(stProcedures, '', '');
 3: sqldsSchemaInfo.SetSchemaInfo(stColumns, 'COUNTRY', '');
 4: sqldsSchemaInfo.SetSchemaInfo(stProcedureParams, 'ADD_COUNTRY', '');
 5: sqldsSchemaInfo.SetSchemaInfo(stIndexes, 'COUNTRY', '');
 end; // case
 
 sqldsSchemaInfo.Open;
 cdsSchemaInfo.Open;
end;

In the example, we use the selection in TRadioGroup component to determine which type of schema information we want. We then call the SetSchemaInfo() procedure using the proper SchemaType parameter before opening the dataset. The values are stored in a TDBGrid in the example.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.