Database Engines:ads

Query field properties Professional

When connecting to the Advantage Database Server and using a dictionary connection extended attributes such as field description and validation rules are available. The table below lists the DAC constants supported by the ADSDBE.

Access to the extended attributes is provided through the :setProperty() method of the DacField() class.

DacField() extended properties
Constant *) Description
DAC_FIELD_NULLABLE ro if .T. field is nullable
DAC_FIELD_READONLY ro if .T. field is read only
DAC_FIELD_DEFAULT ro default value for append operation
DAC_FIELD_DESCRIPTION ro descriptive text for field
DAC_FIELD_RULE ro validation rule
DAC_FIELD_RULEMESSAGE ro message if validation rule is violated
  1. ro = read only, rw = read write

DAC_FIELD_NULLABLE

If .T. field can be nullable, NIL can be assigned and NIL is a valid "value" of the database field. Note that ADT tables always default to DAC_FIELD_NULLABLE = .T.

DAC_FIELD_READONLY

If .T. the database field can only read. An attempt to write to the field will raise an runtime error. If.F. read and write operation with the database field are allowed. Note that fields of type AUTOINC are always readonly.

DAC_FIELD_DEFAULT

If specified this is the default value of the database field at append or insert operations.

DAC_FIELD_DESCRIPTION

Holds a descriptive text for the specific database field.

DAC_FIELD_RULE

The Advantage Database Server supports validation rules for fields. Using the Advantage Dictionary one can specify a maximum and minimum value for a specific database field. The ADSDBE automatically creates a valid Xbase++ expression to be used by the client application. If for example your table CUSTOMER has an AGE field of type numeric and the dictionary has stored a min value of 1 and a max value of 120 the validation rule returned is "FIELD->AGE >=1 .AND. FIELD->AGE <= 120". The rule expression returned can be used by the client application to perform input validation on the client side instead of relaying on the validation mechanism of the Advantage Database Server.

It is considered a good practice to perform input validation as soon as the user enters data, instead of relying on the server side validation which happens only when a commit operation takes place.

DAC_FIELD_RULEMESSAGE

This is the message the application can show to the user if the validation rule is violated.

The following sample code illustrates how DacField() objects can be retrieved and this way access to the extended attributes provided by the Advantage Data Dictionary can be achieved.

01: #include "dac.ch" 
02: #include "adsdbe.ch" 
03: 
04: #pragma library("adac20b.lib") 
05: 
06: PROCEDURE MAIN 
07: 
08: // establish a dictionary connection to the the SALES database 
09: // 
10: oSession := DacSession():New("DBE=ADSDBE";SERVER=\\alaska01\somewhere\sales.add") 
11: 
12: // open tables 
13: // 
14: USE Customer VIA oSession 
15: USE Orders VIA oSession 
16: 
17: // assuming the customer table has an AGE field 
18: // the DacField object can be retrieved as following: 
19: // 
20: oAge := DacField():QueryObject("CUSTOMER->AGE") 
21: 
22: // assuming customer has a ZIP Code field the DacField 
23: // object can be retrieved through the dataset reflecting 
24: // the workarea. 
25: // 
26: oCustomer := DacSDataset():QueryObject("CUSTOMER") 
27: oZip      := oCustomer:QueryField("ZIPCODE") 
28: 
29: // access to extended field attributes is provided through 
30: // the :setProperty() method of the object 
31: // 
32: ? "Description:", oAge:setProperty(DAC_FIELD_DESCRIPTION) 
33: ? "Rule       :", oAge:setProperty(DAC_FIELD_RULE) 
34: 
33: RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.