Database Explorer Interface

The appearance of the Explorer closely matches the format seen in the BDE Administrator. Figure 4.16 shows the dual-paned window used for all actions in the Explorer. The left pane contains two tabs: the Databases tab listing all database aliases defined to the BDE and the Dictionary tab showing the contents of the data dictionaries that have been defined.

Figure 4.1 6 The. Database Explorer

ffi-ï CflSS CRSYB É-jS dBASE Fies DBBOEMOS S É] Tables

Type

Date

Time

Version

Paradox

12/9/1998

2:07:56 PM

ffi-ï CflSS CRSYB É-jS dBASE Fies DBBOEMOS S É] Tables

SHU neighbor.dbl é-H REGISTER.db 0 | Fields Sh-g) Indices S--ÊS VaSdity Checks ~fj3 Refefential Constraints Security Specs S Family Members ffl^Q- —

B lft DefautDD ExcdFies

Type

Date

Time

Version

Valid

Structure

Protected

Table Type

Paradox

12/9/1998

2:07:56 PM

Paradox 7.0. heap

The contents of the right-hand pane vary according to the object selected in the left-hand pane. The number of tabs and their descriptions will change with the choice of more detailed selections. Status bars are displayed above each of the panes, giving you a summary description of what you are currently viewing.

The hierarchical viewing capabilities are constrained to the left pane. In this window, the developer can drill down to increasingly detailed levels of information about the database selected. In Figure 4.17, the DBBDEMOS database has been expanded from the root of the hierarchy by clicking on the plus sign next to the name. When a database is selected, the detail in the right pane will be the alias information defined when it was established. As shown, the next items listed are the tables that make up this database. Each of the tables is also prefaced with a plus sign, indicating that there is further detail about each of them available.

Data Dictionary

The detail for the REGISTER table, built earlier in this chapter, has been expanded. The number and names of the nodes that appear will differ for each of the supported table types. The Fields node in the example is expanded to show all of the fields that were defined for the table. Selecting the field narrows the information down to the field definition. Information also available for the Paradox table includes the Indices, Validity Checks, Referential Constraints, Security Specifications, and Family Members. Perhaps most importantly, the data that the table contains can be modified and examined.

The Database Explorer can also be used to establish a new alias. The methodology is the same as that used for the BDE Administrator.

Data Dictionary

The ability to create and utilize a data dictionary is a distinct advantage of the BDE/Delphi development tool. A data dictionary is a database that is used to store attribute sets for field components. Attribute sets determine the field type, properties, and the data-aware component that should be generated whenever a TField object is dragged to a form from the Fields Editor. A data dictionary containing an attribute set means that you will only need to set properties once to have them propagated throughout your project.

Chapter 4—The Borland Database Engine and the Database Utilities □ 95

This tool displays its use when you have several columns in a database that share common formatting properties. An extended attribute set can be set once for such things as the alignment, picture string, and minimum and maximum values, and then be associated with multiple fields in your application. If a change is necessary it can be made once through the Explorer and it will then flow to all of the components that use it at once.

Attribute sets can be changed both through the Database Explorer and the Fields Editor. The editor will be discussed in conjunction with the components it services in a later chapter; right now we will focus on creating an attribute set through the Explorer. The first thing to be done is to create a new dictionary Start the Database Explorer, either from the Start menu or from within Delphi, using the Tools menu.

Select the Dictionary tab in the left-hand pane.

Bight-click on the Dictionary entry and select New. Alternately, you may select New from the Object menu. The dialog shown in Figure 4.18 will be displayed.

Figure 4.18 Information for « new dictionary in the Create a New Dictionary

Figure 4.18 Information for « new dictionary in the Create a New Dictionary

Enter the data shown in the example dialog. The Description field is optional. Click OK to save the new dictionary.

You can create multiple dictionaries as needed to support your development needs. Only one dictionary is displayed at a time; the Database Explorer does not extend its hierarchical display to this feature. To work with alternate dictionaries, select Dictionary | Select from the menu and choose the dictionary name from the drop-down box.

Establishing the attribute sets that make up the contents of the new dictionary is the next step. Attribute sets can be created manually or imported from databases or SQL constraint sets. Before establishing an attribute set, it is helpful to view an exceptional example provided by Borland. This dictionary is linked to the examples provided with the Delphi package so they must be installed prior to exploring this item.

96 ■ Part li—The Delphi Database Tools

Select Dictionaryl Select from the menu and choose the Borland Data Dictionary; click OK to open it. Expanding the Databases node informs you that this dictionary is used for the DBBDEMOS database, the demonstration tables included with Delphi. There's not much of interest under that node but plenty to look at by expanding the Attribute Sets node. You will discover a number of attribute sets defined. Expand the VendorNo node to find two nodes that follow: Referencing Fields and Referencing Attribute Sets. Select the VendorNo field itself to open the attribute definition shown in Figure 4.19.

Figure 4. 19 The Definition tab for setting attributes

Figure 4. 19 The Definition tab for setting attributes

A daunting number of possibilities present themselves for modification of the attribute set. Each of the choices is explained in Figure 4.20.

Attribute

Definition

Attribute

TControlClass

Alignment

This determines the type of field to create when a field is added to a dataset. When left blank, the physical data type determines the type of field to create.

This determines the type of control to create when a field is dragged to a form. When left blank, the physical data type determines the type of control to create.

Determines the alignment of the data in an edit or grid control. Options are center, left, or right alignment.

Chapter 4—The Borland Database Engine and the Database Utilities ■ 97

Attribute

Definition

When the field is displayed in a grid control, the field name is the default column heading. The entry in this parameter replaces the default value.

This determines the number of characters used to display a field in a grid control.

This determines if a field can be edited or if it is read only. Values are True/False.

This determines if the field requires an entry. Values are True/False.

Visible

This determines whether or not a field can be displayed in a grid control. Values are True/False.__

Transliterate

This determines whether or not a field type is translated between types in different databases. Values are True/False.

Edit Mask

DisplayFormat

This value contains the Edit mask, the formatting character string that determines how data can be entered into an edit box._

The value in this field determines how the field value is disçlayed..

EditFormat

This determines how numeric values appear when edited in a data-aware control.

This sets a minimum allowable value for the field.

MaxValue

Currency

This sets a maximum allowable value for the field.

When set to "True, this indicates that the values entered in this field are currency values.

Precision

Displa/Values

This determines the number of decimal positions that are formatted prior to being rounded off.

This determines the translation of values in a Tboolean field to and from the display format.

BlobType

This field specifies the type of blob associated with a memo or graphic control.

This specifies a default SQL value for the field when it is left empty during data entry._

This specifies a SQL string that enforces a value constraint on the field.

This determines the custom message that is displayed when the CustomConstraint is violated.

This specifies a different attribute set from which the current set is based. The settings in the current set override the originals.

Figure 4.20 Extended attributes for the TField objects

98 ■ Part il-~The Delphi Database Tools

The entry for the field VendorNo contains some interesting examples of the level of control that can be exercised through the data dictionary. Note first the DisplayFormat. The entry contains the value "VN 0000," which translates into a literal string of "VN" followed by the vendor number that you want to assign. It is important to remember that this differs from the EditFormat entry, especially when you are entering data. When a new value is entered for the vendor number, the "VN" will not appear until after the value is accepted.

The value acceptable for this field is constrained by the CustomConstraint SQL string. This field contains any valid SQL string that you wish to use to validate or otherwise constrain the data for this field. Values entered that violate this constraint will cause an exception to be raised. When the exception occurs, the error message contained in the Error String field is displayed, overriding the default exception message.

Below the entry for the VendorNo field are two more nodes. Expanding the Referencing Fields node demonstrates the usefulness of the data dictionary Notice that two fields in entirely separate tables reference the extended attributes set for the vendor number. By setting the parameters for a field once, we are able to reuse the attribute set for any similar field. Whether the data item is the same, as is the case with the vendor number, or different data items with similar formatting, a single entry in the data dictionary can format multiple fields. When the settings need to be modified, expanding the range of allowable values for the vendor number for example, the modification is made at a single point rather than at each field in the database. This saves enormous time and makes for much cleaner code.

The REGISTER database is a comfortable place to establish our first attribute set. The attributes that are going to be set will be used for verification of the Date of Birth field (renamed DOB for simplicity's sake). After reopening the dictionary DemoDictionary created earlier in this chapter, follow these initial steps to establish a new attribute set:

Expand the nodes of the dictionary by clicking on the plus sign. You should have two empty nodes: Databases and Attribute Sets.

Right-click on the Attribute Sets node and select New from the context menu. A new attribute set called EXTFIELD1 will be opened.

While the set name is highlighted, rename it DOBField.

Three items in the attribute set are going to be modified for this field. Figure 4.21 is the right-hand pane of the Database Explorer showing the completed items.

Chapter 4-The Borland Database Engine and the Database Utilities

Transliterate

EditMask

Disptajfotroat

EdkFocmat mmmm dd, yyyy

Figure 4.2 I The Definition tab for setting attributes

Transliterate

EditMask

Disptajfotroat

EdkFocmat

MinValue

MaxValue

Currency

Preciaon

DisplayValues

BlobType

DefaultExpfession

CustomConstraint

ConstraintE norM essage

Based On mmmm dd, yyyy

{REGISTER.DOB >= '08/31/93') AND (REGISTER.DOB <= '08/31/94')

Student birthdate is out of fange. Please verify.

The first entry will be to modify DisplayFormat. We are going to change the way the date is displayed. This will not affect the way in which data is entered. Change this parameter to read mmmm dd, yyyy by typing this directly into the property area. When this field is displayed in a grid or edit control, this attribute will cause the date of birth to be displayed as the full name of the month followed by the day, a literal comma, and the year displayed with the century. Because we have not modified EditMask or EditFormat, the field will still accept the default MM/DD/YY format for input purposes.

Next, we are going to turn our attention to the CustomConstraint parameter. This field allows us to enter a SQL statement that will validate any data entered into this field. For the start of the 1999 school year, a student should have been born prior to August 31, 1994 and no earlier than August 31, 1993, which would make him too old to be just starting school. Enter the SQL statement that will verify this in the CustomConstraint field:

(REGISTER.DOB > = «08/31/930 AND (REGISTER.DOB < = «08/31/94')

Finally, add an explanatory error message to the attribute that is displayed when the CustomConstraint is triggered. Enter the message Student birthdate is out of range. Please Verify, in the field.

Click Apply or select Object | Apply from the menu to save your changes. Close the Database Explorer.

Figure 4.22 Database Breadboard dialog

Figure 4.23 The Associate Attributes dialog

In order to apply these attributes to a field object, the dictionary must be associated directly with the TFieldl object. The project DBTEST (included on the Cd) will provide the basis for testing the attribute set just created.

The main form for the project is shown in Figure 4.22,

Figure 4.22 Database Breadboard dialog

Invoke the Fields Editor from the Table II component by double-clicking on it. If the columns of the REGISTER table do not appear in this form, right-click on the Fields Editor to invoke the context menu. From the context menu, select Add All Fields, Your next step in utilizing the attribute set from the dictionary is to associate the definitions with the fields of a table.

Click on the DOB field, Notice in the Object Inspector that a different set of properties has been exposed. These are the TField! specific properties.

Right-click on the DOB field and select Associate attributes from the context menu The Associate Attributes dialog will appear as shown in Figure 4.23. The single attribute set that we defined, DOBField, will appear for selection. Click OK.

Figure 4.23 The Associate Attributes dialog

Chapter 4—The Borland Database Engine and the Database Utilities ■ 10 I

  1. The properties in the Object Inspector that relate to the attribute set properties will now be filled with the parameters from the data dictionary
  2. Close the Fields Editor and compile the project.

Test the project by entering various dates in the DOB field. The error message defined earlier will appear for each date that falls outside of the range. You will also discover that the validity checks set in earlier sections are in place. For example, the row will not be accepted without a Social Security number.

One critical caveat must be remembered when updating your attribute sets. The changes will not automatically be associated with the TField objects. You must associate the new attribute sets with the objects and recompile your project before the changes will appear in the execut-able-a small price to pay for the flexibility offered through a data dictionary

Was this article helpful?

0 0

Post a comment