Board index » delphi » Sybase autoincrement fields and Delphi 3

Sybase autoincrement fields and Delphi 3

Question: How can I use an auto increment field in a Sybase table with D3?

In sybase I've made these setting to the column properties:
- 'Column type'
   Data type:      integer
- 'Advanced Column Properties'
   Default value:  Pre-defined  autoincrement
   Constraints:    Values are unique
                   Don't allow NULL

In D3, when I add the field to the tTable it will be typed
'tIntegerField' and *not* 'tAutoIncField'... (why?)

When I Append and Post a record an exception will occur, stating that
the field must have a value.

I've also tried tField.SetFieldType(ftAutoInc) but this makes no
difference.

I think Delphi does not recognize the table column as autoincrement in the
first place.

Marz
i...@xs4all.nl

 

Re:Sybase autoincrement fields and Delphi 3


The problem with AutoInc fields is that they happen once an insert happens on
the DATABASE not the dataset.  When you do a post to record in a TDataSet, you
are first posting to the dataset and then, if it is a live non-cached dataset,
it will attempt to write that record to the database. Typically, an autoinc
field is a key field and as such, when Delphi creates the meta-data for the
field, it will declare it as a required field.  The problem with this is that
required fields are checked in the dataset before the insert occurs on the
database.

Solution:  In the fields editor, try setting the Required property to False
for the AutoInc field.  This sounds illogical since it is a required field,
its just that your application is not supplying that field, but rather the
database will supply it.

-Trevor

Quote
Marz wrote:
> Question: How can I use an auto increment field in a Sybase table with D3?

> In sybase I've made these setting to the column properties:
> - 'Column type'
>    Data type:      integer
> - 'Advanced Column Properties'
>    Default value:  Pre-defined  autoincrement
>    Constraints:    Values are unique
>                    Don't allow NULL

> In D3, when I add the field to the tTable it will be typed
> 'tIntegerField' and *not* 'tAutoIncField'... (why?)

> When I Append and Post a record an exception will occur, stating that
> the field must have a value.

> I've also tried tField.SetFieldType(ftAutoInc) but this makes no
> difference.

> I think Delphi does not recognize the table column as autoincrement in the
> first place.

> Marz
> i...@xs4all.nl

  vcard.vcf
< 1K Download

Re:Sybase autoincrement fields and Delphi 3


I use Persistent fields in these cases.

Delphi sees the AutoInc field as Integer, so once the persistent fields
have been created, DELETE the field that Delphi incorrectly recognised and
CREATE (using New Field) a field with the SAME NAME, Delphi again will
recognise it incorrectly, so at this stage, force it to AutoInc from the
Picklist.

This will solve that problem. Another related problem is being able to
retrieve the generated value. If you don't need to use it immediately, no
problem, else join the club of  frustrated AutoInc field users !

Hope this helps

Warren van Niekerk
Sentient Software c.c.
senti...@icon.co.za

Other Threads