RAD Studio
ContentsIndex
PreviousUpNext
Using dbExpress Components
Name 
Description 
dbExpress is a set of lightweight database drivers that provide fast access to SQL database servers. For each supported database, dbExpress provides a driver that adapts the server-specific software to a set of uniform dbExpress interfaces. When you deploy a database application that uses dbExpress, you need only include a dll (the server-specific driver) with the application files you build.
dbExpress lets you access databases using unidirectional datasets. Unidirectional datasets are designed for quick lightweight access to database information, with minimal overhead. Like other datasets, they can send an SQL command to the database server, and if the command... more 
There are two ways to obtain information about what is available on the server. This information, called schema information or metadata, includes information about what tables and stored procedures are available on the server and information about these tables and stored procedures (such as the fields a table contains, the indexes that are defined, and the parameters a stored procedure uses).
The simplest way to obtain this metadata is to use the methods of TSQLConnection. These methods fill an existing string list or list object with the names of tables, stored procedures, fields, or indexes, or with parameter descriptors. This... more 
The first step when working with a dbExpress dataset is to connect it to a database server. At design time, once a dataset has an active connection to a database server, the Object Inspector can provide drop-down lists of values for other properties. For example, when representing a stored procedure, you must have an active connection before the Object Inspector can list what stored procedures are available on the server.
The connection to a database server is represented by a separate TSQLConnection component. You work with TSQLConnection like any other database connection component.
To use TSQLConnection to connect a... more 
Most of the commands that do not return data fall into two categories: those that you use to edit data (such as INSERT, DELETE, and UPDATE commands), and those that you use to create or modify entities on the server such as tables, indexes, and stored procedures.
If you don't want to use explicit SQL commands for editing, you can link your unidirectional dataset to a client dataset and let it handle all the generation of all SQL commands concerned with editing. In fact, this is the recommended approach because data-aware controls are designed to perform edits through a dataset... more 
While you are debugging your database application, it may prove useful to monitor the SQL messages that are sent to and from the database server through your connection component, including those that are generated automatically for you (for example by a provider component or by the dbExpress driver). 
You can use a dbExpress dataset even if the query or stored procedure it represents does not return any records. Such commands include statements that use Data Definition Language (DDL) or Data Manipulation Language (DML) statements other than SELECT statements (For example, INSERT, DELETE, UPDATE, CREATE INDEX, and ALTER TABLE commands do not return any records). The language used in commands is server-specific, but usually compliant with the SQL-92 standard for the SQL language.
The SQL command you execute must be acceptable to the server you are using. Unidirectional datasets neither evaluate the SQL nor execute it. They merely pass... more 
To execute a query or stored procedure that does not return any records, you do not use the Active property or the Open method. Instead, you must use
The ExecSQL method if the dataset is an instance of TSQLDataSet or TSQLQuery.  
To populate a unidirectional dataset with metadata from the database server, you must first indicate what data you want to see, using the SetSchemaInfo method. SetSchemaInfo takes three parameters:
  • The type of schema information (metadata) you want to fetch. This can be a list of tables (stTables), a list of system tables (stSysTables), a list of stored procedures (stProcedures), a list of fields in a table (stColumns), a list of indexes (stIndexes), or a list of parameters used by a stored procedure (stProcedureParams). Each type of information uses... more 
Once you have specified the source of the data, you must fetch the data before your application can access it. Once the dataset has fetched the data, data-aware controls linked to the dataset through a data source automatically display data values and client datasets linked to the dataset through a provider can be populated with records.
As with any dataset, there are two ways to fetch the data for a dbExpress dataset:
One way is to set the Activeproperty to True, either at design time in the Object Inspector, or in code at runtime:  
When you want to represent all of the fields and all of the records in a single underlying database table, you can use either TSQLDataSet or TSQLTable to generate the query for you rather than writing the SQL yourself.
Note: If server performance is a concern, you may want to compose the query explicitly rather than relying on an automatically-generated query. Automatically-generated queries use wildcards rather than explicitly listing all of the fields in the table. This can result in slightly slower performance on the server. The wildcard (*) in automatically-generated queries is more robust to changes in the fields... more 
Using a query is the most general way to specify a set of records. Queries are simply commands written in SQL. You can use either TSQLDataSet or TSQLQuery to represent the result of a query.
When using TSQLDataSet, set the CommandType property to ctQuery and assign the text of the query statement to the CommandText property. When using TSQLQuery, assign the query to the SQL property instead. These properties work the same way for all general-purpose or query-type datasets. Specifying the query discusses them in greater detail.
When you specify the query, it can include parameters, or variables,... more 
Stored procedures are sets of SQL statements that are named and stored on an SQL server. How you indicate the stored procedure you want to execute depends on the type of unidirectional dataset you are using.
When using TSQLDataSet, to specify a stored procedure:
  • Set the CommandType property to ctStoredProc.
  • Specify the name of the stored procedure as the value of the CommandText property:
 
There are two ways to use linked datasets to set up a master/detail relationship with a dbExpress dataset as the detail set. Which method you use depends on the type of unidirectional dataset you are using. Once you have set up such a relationship, the unidirectional dataset (the "many" in a one-to-many relationship) provides access only to those records that correspond to the current record on the master set (the "one" in the one-to-many relationship).
TSQLDataSet and TSQLQuery require you to use a parameterized query to establish a master/detail relationship. This is the technique for creating such relationships on all... more 
In order to describe a database connection in sufficient detail for TSQLConnection to open a connection, you must identify both the driver to use and a set of connection parameters the are passed to that driver. 
With unidirectional datasets, the way you specify the command to execute is the same whether the command results in a dataset or not. That is:
When using TSQLDataSet, use the CommandType and CommandText properties to specify the command:
  • If CommandType is ctQuery, CommandText is the SQL statement to pass to the server.
  • If CommandType is ctStoredProc, CommandText is the name of a stored procedure to execute.
When using TSQLQuery, use the SQL property to specify the SQL statement to pass to the server.
When using TSQLStoredProc, use the StoredProcName property to specify the name of the stored procedure... more 
There are a number of ways to specify what data a dbExpress dataset represents. Which method you choose depends on the type of unidirectional dataset you are using and whether the information comes from a single database table, the results of a query, or from a stored procedure.
When you work with a TSQLDataSet component, use the CommandType property to indicate where the dataset gets its data. CommandType can take any of the following values:
  • ctQuery: When CommandType is ctQuery, TSQLDataSet executes a query you specify. If the query is a SELECT command, the dataset contains the resulting... more 
The dbExpress category of the Tool palette contains four types of unidirectional dataset: TSQLDataSet, TSQLQuery, TSQLTable, and TSQLStoredProc.
TSQLDataSet is the most general of the four. You can use an SQL dataset to represent any data available through dbExpress, or to send commands to a database accessed through dbExpress. This is the recommended component to use for working with database tables in new database applications.
TSQLQuery is a query-type dataset that encapsulates an SQL statement and enables applications to access the resulting records, if any.
TSQLTable is a table-type dataset that represents all of the rows and columns... more 
For each type of metadata you can access using TSQLDataSet, there is a predefined set of columns (fields) that are populated with information about the items of the requested type. 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!