Subject RE: [IBO] Default value X Query Insert
Author Norman Dunbar
-----Original Message-----
From: emgfyah2002 [mailto:edison@...]
Sent: Tuesday, April 09, 2002 2:35 PM
To: IBObjects@yahoogroups.com
Subject: Re: [IBO] Default value X Query Insert


>> Dear Norman
>> Thank you very much. It works. As a matter of fact, the 'Required'
>> was grayed, but after I clear it, no more problems.

This is good - I have now accomplished one useful thing today :o)
I'm not having a good day at work - been on holiday and stacks of stuff is
piled up for me :o(.


>> I have a table which primary key is
>> generated by a before insert trigger:
>> BEGIN
>> IF (NEW.COR IS NULL) THEN
>> NEW.COR = GEN_ID(GEN_TABCOR_ID,1);
>> END

I'm sure this is fine - I presume that the column COR is defined as being an
interger or numeric ?

I tend to put triggers on the database to trap when I am inserting stuff via
SQL and not from the client application. So, I'd have the trigger as defined
to trap that, and in my client application, I would use a 'GeneratorLinks'
setting. This can be set as follows :

doubleclick the query
click on the sql tab
if you have a valid sql statment, prepare it by clicking on the 'light bulb'
icon.
Now click on the 'masterlinks' tab (on the bottom row of tabs).
In the 'generatorlinks' area, put this :

table_name.column_name=generator_name

There should be no spaces around the equals sign. An example :

artist.id=gen_artist

Alternatively, there is a proprty on the Query called GeneratorLinks. Click
on it and enter the above directly into the property editor that comes up.

Now, all else being equal, the setting for 'REQUIRED' is irelavant because
IBO does it all for you. When you insert a row, IBO fetches the next
generator value and inserts it into the ID field. You can see this on a grid
where the id number appears before you get a chance to type in the rest of
the data. If the id column was not required (but showing in the grid) you
wouldn't see a value in the grid for it.

Now your trigger never gets fired by the client application, but will/should
do if someone does an 'insert into table_name (column_names) values (x,y,z
...) and doesn't put in the id column.


>> Thank you
>> Edison

You're welcome.

By the way, have you obtained the Getting Staterd Guide yet ?
If not, it comes highly recommended. There are examples, explanations, code
(in C++ and in Delphi) and much much more.
You *do* have to pay, but it is well worth it.

Cheers,
Norman.

-------------------------------------
Norman Dunbar
Database/Unix administrator
Lynx Financial Systems Ltd.
mailto:Norman.Dunbar@...
Tel: 0113 289 6265
Fax: 0113 289 3146
URL: http://www.Lynx-FS.com
-------------------------------------

This email is intended only for the use of the addressees named above and
may be confidential or legally privileged. If you are not an addressee you
must not read it and must not use any information contained in it, nor copy
it, nor inform any person other than Lynx Financial Systems or the
addressees of its existence or contents. If you have received this email
and are not a named addressee, please delete it and notify the Lynx
Financial Systems IT Department on 0113 2892990.