Product Documentation

c-treeACE V11.0 Update Guide

Previous Topic

Next Topic

Extended c-treeDB Default Field Value Support

In V11 and later, it is possible to set default field values using functions such as SYSDATE, SYSDATETIME, etc. Previously, c-treeDB only supported defining default values for fields using literal values. This improves c-treeDB compliance with SQL, where it is possible to set default field values with literals or with functions.

A new enum, CTDEF_TYPE, has been added to use with these new functions:

CTDBRET ctdbDECL ctdbSetFieldDefaultValueType(CTHANDLE Handle, CTDEF_TYPE def_type);

Sets the default value type.


CTDEF_TYPE ctdbDECL ctdbGetFieldDefaultValueType(CTHANDLE Handle);

Gets the default value type.

Valid def_types are:

CTDEF_LITERAL: the value is a literal

CTDEF_USER: the current* user name

CTDEF_NULL: null

CTDEF_SYSDATE: the current* date

CTDEF_SYSTIME: the current* time

CTDEF_SYSTIMESTAMP: the current* timestamp

* “current” means at the time the default gets evaluated to be stored in the field.

To set the default value as a literal and automatically set its type to CTDEF_LITERAL, use a call to ctdbSetFieldDefaultValue.

To set the default value to any of the supported SQL functions, use a call to ctdbSetFieldDefaultValueType and pass the desired type, e.g. CTDEF_SYSDATE.

Default Values with ALTER TABLE

ctdbAlterTable has been enhanced to properly set the default value in new fields when doing a full rebuild.

ctdbAlterTable logic has been slightly changed so that the default value gets applied only to the fields just added, not to existing fields for which it may have been added or changed. Before this modification, existing fields could unintentionally change their values from NULL to the default value.

TOCIndex