Subject |
Re: setting default value of fields |
From |
Ken Mayer <dbase@nospam.goldenstag.net> |
Date |
Sat, 6 Jul 2024 07:44:03 -0700 |
Newsgroups |
dbase.getting-started |
On 7/6/2024 5:45 AM, Mervyn Bick wrote:
> 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 := " "
> endif
> if empty(this.fields['qty'].value)
> this.fields['qty'].value := 0
> endif
> return
I'd suggest onAppend, actually ... then you can make it even simpler:
function rowset_onAppend()
this.fields['code'].value := ""
this.fields['qty'].value := 0
return
Ken
--
*Ken Mayer*
Ken's dBASE Page: http://www.goldenstag.net/dbase
The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm
dBASE Web Tutorial: http://www.goldenstag.net/dbase/WebTutorial/00_Menu.htm
dBASE DOS to Windows Tutorial:
http://www.goldenstag.net/dbase/DtoWTutorial/00_Menu.htm
|
|