f2s_column_default_sql_value¶
Applies to: Oracle, MS SQL, MySql/MariaDB, PostgreSQL Drivers
Syntax
set_attribute f2s_column_default_sql_value of {FileNumber} {FieldNumber} to {variable}
get_attribute f2s_column_default_sql_value of {FileNumber} {FieldNumber} to {variable}
Parameter |
Description |
---|---|
FileNumber |
Number of the file (filename.File_Number) |
FieldNumber |
Number of the field (field field name) |
variable |
String variable. The default value for the field. |
Description
This attribute is used to get or set the default value for a given column. Getting the default value can be done anywhere in the code, however, setting the value can only be done within a Structure_Start/Structure_End block.
Different databases use different formats for the default values. If the variable is malformed, the default value for the column will be deleted but NOT recreated. No error is generated.
When creating a table, if the attribute is not set, it is defaulted to the driver default. For more information, please see Mertech.cfg.
All supported versions of SQL Server, Oracle, and PostgreSQL support either constants or expressions as defaults. For MySQL, expressions can be used as default values only on v8.0.13+. For MariaDB expressions can be used as default values in v10.2.1+ For MySQL or MariaDB, expressions cannot be used as defaults values on columns that are part of the primary key.
Examples
get_attribute
Handle hOrderHea
Integer iDate
String sDefault
Move OrderHeader.File_Number to hOrderHea
Field_Map hOrderHea "Order_Date" to iDate
Get_Attribute f2s_column_default_sql_value of hOrderHea iDate to sDefault
set_attribute
Handle hOrderHea
Integer iDate
String sDefault
Move OrderHeader.File_Number to hOrderHea
Field_Map hOrderHea "Order_Date" to iDate
Get_Attribute f2s_column_default_sql_value of hOrderHea iDate to sDefault
Showln (SFormat("The Default value for Date is %1", sDefault))
Structure_Start hOrderHea _f2s_ActiveDriver
//This would NOT work using f2s_column_default_sql_value_legacy
Set_Attribute f2s_column_default_sql_value of hOrderHea iDate to "GetDate()"
Structure_End hOrderHea DF_STRUCTEND_OPT_NONE "." 0
Open OrderHeader
Move OrderHeader.File_Number to hOrderHea
Field_Map hOrderHea "Order_Date" to iDate
Get_Attribute f2s_column_default_sql_value of hOrderHea iDate to sDefault
Showln (SFormat("The Default value for Date is %1", sDefault))
Related Attributes
Replaces: DF_FIELD_DEFAULT_FUNCTION