DF_FIELD_PROGRAMMATIC_DEFAULT

Applies to: Oracle, MS SQL, MySql, MariaDB, PostgreSQL Drivers

Syntax

set_attribute DF_FIELD_PROGRAMMATIC_DEFAULT of {FileNumber} {FieldNumber} to {variable}
get_attribute DF_FIELD_PROGRAMMATIC_DEFAULT of {FileNumber} {FieldNumber} to {variable}

Parameter

Description

FileNumber

Number of the file (filename.File_Number)

FieldNumber

Number of the column (based on order in FD file)

variable

Variant Value. Contains the value that will be used as a default or find constraint.

Description

This attribute is somewhat like a default in that the value will be used during record creation if a value is not given for the specified column. Unlike a default, this value is also used alongside the command SET_SQL_CONSTRAINT (using the FROM_PROGRAMMATIC_DEFAULTS parameter) to constrain find operations as well. This gives an easy way for an application to be converted to a multi-company setup without requiring extensive code changes (as these settings are global unlike DD defaults for instance).

Note

  • If SET_SQL_CONSTRAINT is used on the table with the parameter being a constraint, DF_FIELD_PROGRAMMATIC_DEFAULT won’t be used for find operations. You must remember to manually add your constraints if they apply.

  • The variable passed in SET_SQL_CONSTAINT can be a blank string. The attribute DF_FIELD_PROGRAMMATIC_DEFAULT can be set to blank as well.

Do NOT do the following:
set_attribute DF_FIELD_PROGRAMMATIC_DEFAULT of Myfile.File_number MyFieldNumber to ""
SET_SQL_CONSTRAINT of Myfile.File_Number FROM_PROGRAMMATIC_DEFAULTS
it will throw an exception. To clear the constraint use:
SET_SQL_CONSTRAINT of Myfile.File_Number to ""

Example

In this example, the field Company has been added to the Customer table. For all of the records, the Company value has been set to “Some Company”. When DF_FIELD_PROGRAMMATIC_DEFAULT is set to “Another Company”, the new record created will have the Company field set with “Another Company”. When When there is no contraint (default), all the records in the table are returned during a find. Later when the the constaint is set to FROM_PROGRAMMATIC_DEFAULTS only that record is returned in the find.

 integer FieldNum
 string sConstraint

 Open customer
 Field_Map CUSTOMER.File_Number "Company" to FieldNum

 //Set the default for the Company name
 Set_Attribute DF_FIELD_PROGRAMMATIC_DEFAULT of CUSTOMER.File_Number FieldNum to "Another Company"

 Clear CUSTOMER
 Move "Carols Coffee" to Customer.Name
 Move "1 Cafe Lane" to CUSTOMER.Address
 Move "Latte City" to CUSTOMER.CITY
 Move "MN" to CUSTOMER.STATE
 Move '56512' to CUSTOMER.ZIP
 Move "New Customer" to CUSTOMER.COMMENTS
 SaveRecord CUSTOMER

 //do a find
 GET_SQL_CONSTRAINT of customer.File_number to sConstraint
 showln (sFormat("Constraint is %1", sConstraint))
 Clear CUSTOMER
 Find ge CUSTOMER by Index.1
 While (Found)
     Showln (SFormat("Customer:  %1; Company: %2", Trim(CUSTOMER.NAME), Trim(CUSTOMER.Company)))
     Find gt CUSTOMER by Index.1
 Loop


 SET_SQL_CONSTRAINT of customer.File_number to FROM_PROGRAMMATIC_DEFAULTS
 GET_SQL_CONSTRAINT of customer.File_number to sConstraint
 showln (sFormat("Constraint is %1", sConstraint))
 //do a find
 Clear CUSTOMER
 Find ge CUSTOMER by Index.1
 While (Found)
     Showln (SFormat("Customer:  %1; Company: %2", Trim(CUSTOMER.NAME), Trim(CUSTOMER.Company)))
     Find gt CUSTOMER by Index.1
 Loop

When run, this example produces:

Constraint is
Customer:  Carols Coffee; Company: Another Company
Customer:  Access Miles; Company: Some Company
Customer:  American Products, Inc.; Company: Some Company
    **** Rest of the data in the table ****
Constraint is  and "Company" = 'Another Company'
Customer:  Carols Coffee; Company: Another Company

Related Attributes