Читайте также: |
|
TSession has a number of methods that enable an application to get database-relatedinformation. Each method takes a TStrings component as its parameter and returns into a TStrings the specified information:
Table 3.1 TSession methods
Method | Returns |
GetAliasNames | Defined BDE alias names. |
GetAliasParams | Parameters for the specified BDE alias. |
GetDatabaseNames | Database names and BDE aliases defined. |
GetDriverNames | Names of BDE drivers installed. |
GetDriverParams | Parameters for the specified BDE driver. |
GetTableNames | All table names in the specified database. |
For more information on these methods, see the online VCL Reference.
Lecture 10. Using datasets
TTable and TQuery component classes are descended from TDataSet through TDBDataSet. These component classes share a number of inherited properties, methods,and events. For this reason, it is convenient to refer to them together as datasets, when the discussion applies to both TTable and TQuery.
This section describes the features of datasets that are common to TTable and TQuery. A subsequent section discusses features unique to TTable.
Note TStoredProc is also a dataset component since it is descended from TDBDataset. Therefore, much of this section also applies to TStoredProc if the stored procedure returns a result set rather than a singleton result.
Dataset states
Table 3.2. Dataset states
State | Description |
Inactive | The dataset is closed. |
Browse | The default state when a dataset is opened. Records can be viewed but not changed or inserted. |
Edit | Enables the current row to be edited. |
Insert | Enables a new row to be inserted. A call to Post inserts a new row. |
SetKey | Enables FindKey, GoToKey, and GoToNearest to search for values in database tables. These methods only pertain to TTable components. For TQuery, searching is done with SQL syntax |
CalcFields | Mode when the OnCalcFields event is executed; prevents any changes to fields other than calculated fields. Rarely used explicitly. |
A dataset can be in the following states, also referred to as modes:
An application can put a dataset into most states by calling the method corresponding to the state. For example, an application can put Table1 in Insert state by calling Table1.Insert or Edit state by calling Table1.Edit. A number of methods return a dataset to Browse state, depending on the result of the method call. A call to Cancel will always return a dataset to Browse state.
CalcFields mode is a special case. An application cannot explicitly put a dataset into CalcFields mode. A dataset automatically goes into CalcFields mode when its OnCalcFields event is called. In OnCalcFields, an exception will occur if an applicationattempts to assign values to non-calculated fields. After the completion of OnCalcFields, the dataset returns to its previous mode.
The following diagram illustrates the primary dataset states and the methods that cause a dataset to change from one mode to another.
Figure 3.2 Dataset state diagram
The State property specifies the current state of a dataset. The possible values correspond to the above states and are dsInactive, dsBrowse, dsEdit, dsInsert, dsSetKey, and dsCalcFields.
The OnStateChange event of TDataSource is called whenever the state of a data source’s dataset changes.
Дата добавления: 2015-10-23; просмотров: 163 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
Controlling database connections | | | Database application development cycle |