Subject Re: setting default value of fields
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 6 Jul 2024 14:45:04 +0200
Newsgroups dbase.getting-started

On 2024/07/06 10:51, Mustansir A Ghor wrote:
> Dear All
> Hope all are good.
> I need to set default value of fields for a new created table programitically, If I use command below, it executes but when I open the same (mODI STRUC) and see the defaulf fields values still shows null.
> CREATE TABLE XYZ (code char(6) default "", qty numeric(6) default 0)
> Can anybody enligthen, if we can set default fields values programatically.
> Best Regards
> Mustansir

Unfortunately CREATE TABLE is a localSQL command and, unlike "proper"
SQL, it doesn't support the DEFAULT option for fields.

It should be possible to use functions from the BDE API (which is what
the table designer in the IDE does behind the scenes) to create a table
and set default values for fields but digging into the BDE API is not
for the fainthearted.

As an alternative you can use the rowset's onSave() event handler to
force values into empty fields.

    function rowset_onSave()
         if empty(this.fields['code'].value)
          this.fields['code'].value := " "
        if empty(this.fields['qty'].value)
           this.fields['qty'].value := 0


Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0