Subject Re: [IBO] Re: default value in table field
Author Helen Borrie
At 10:06 AM 06-06-01 +0000, you wrote:
>Helen
> > It is less costly to give IBO the defaults yourself, using the
> >attribute DEFAULT in the ColumnAttributes of the column. Or you can
> >flag the attribute REQUIRED as false and let the SQL pass without
> >including the column in the GetRequiredFields checking.
> >
> > Another alternative is to omit the column from your insert SQL and
> >have the server populated the computed by or defaulted columns for
> >you.
>
>I omitted this column from IBOTable in this way :
>I opened Fields Editor doubleclicking IBOTable, I included all fields
>and I removed field NFILE_UP. I think that this operation instructs
>IBOTable to process and send to Database only selected fields.
>But it raises exception "NFILE_UP is a required field".

That will NOT work. One of the great limitations of using TIBOTable is that it forces you to have all columns and you can't change that. What I SAID was "omit the column from your insert SQL". That means accessing the InsertSQL property of the underlying TIB_Dataset. To understand what properties are available to you, please read the Help text for that component.

In any case, playing about with the TFields doesn't achieve anything. As I said in my first posting on this problem, you need to access the TIB_Columns underlying your TIBOTable's columns. Each column in your table has a TIB_Column instantiated for it. You can access its properties using FieldByName('TheColumnName') or you can use Fields['TheColumnName'] provided the dataset has been prepared first.

For example, to set off the REQUIRED property for NFILE_UP, you would put this statement in the BeforeInsert event handler:

MyTable.FieldByName('NFILE_UP').Required := False;

Alternatively, you can assign an InsertSQL statement in the BeforePrepare handler:
...
with Sender as TIB_Dataset do
begin
InsertSQL.Add('INSERT INTO MyTable(Field1, Field2,.....) VALUES(:Param1, :Param2, ....'); // but omit NFILE_UP from the field list

>
>I followed your suggestion to set REQUIRED attribute to FALSE as you
>explained in your previous answer :
>I included all fields in the same way I explained above, I selected
>NFILE_UP and set REQUIRED to False.
>I set Table Active to False and soon after to True; Column
>Attribute Required remained set to False.

That's because the Delphi Fields Editor accesses the persistent field objects, not the IB_Columns. By using TIBOTable you are limiting what you are capable of doing in the IDE. The underlying IBO stuff has to be accessed by run-time code.

One way you can set these properties in the IDE is to set them in the FieldsXxxxx... properties in your IBODatabase. Include fetSQLType in its FieldEntryTypes[] property and then go and make entries like, in ColumnAttributes:
MYTABLE.NFILE_UP=NOTREQUIRED

>I removed NFILE_UP from
>DBGrid and it remained only into Table Definitions.
>I get the same exception.

That doesn't solve anything... DBGrid is just a container for displaying what is in the dataset. It doesn't have any bearing on the attributes of the data in the database.

Privately I'll send you a draft of a Tech Info sheet about the TIB_StringProperty objects that are used by TIB_Dataset. But DO read the Help text for the native dataset classes!!!

Helen

All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________