Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Recognation of AutoInc field for Firebird 2.5



Permlink Replies: 6 - Last Post: Jan 25, 2017 4:00 AM Last Post By: Norbert Meier
Norbert Meier

Posts: 19
Registered: 11/26/01
Recognation of AutoInc field for Firebird 2.5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2017 2:44 AM
Hello,

I've a Firebird database with a table that include an "ID" column that is the Primary key column and it's value is generated by a before insert Trigger by using a Generator:

FireDAC (TFDtable) does not recognize this column as an autoinc field, although I set

ExtendedMetaData = True

I looked at:

[http://docwiki.embarcadero.com/RADStudio/Berlin/en/Auto-Incremental_Fields_(FireDAC)]

[https://forums.embarcadero.com/thread.jspa?messageID=868487󔂇]

but I must use

FDTable1.UpdateOptions.AutoIncFields := 'ID';

What could be the reason why FireDAC does not recognize the column as AutoInc field?

Thanks
Norbert
Dmitry Arefiev

Posts: 1,406
Registered: 12/7/03
Re: Recognation of AutoInc field for Firebird 2.5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2017 9:40 PM   in response to: Norbert Meier in response to: Norbert Meier
1) Check that fiMeta is included into FetchOptions.Items
2) Please provide DDL for your table and trigger

--
With best regards,
Dmitry
Norbert Meier

Posts: 19
Registered: 11/26/01
Re: Recognation of AutoInc field for Firebird 2.5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 24, 2017 12:24 AM   in response to: Dmitry Arefiev in response to: Dmitry Arefiev
Dmitry,

I've uploaded a small demo application in attachments

See
[https://forums.embarcadero.com/thread.jspa?messageID=874213&#874213]

The FetchOptions.Items include fiMeta.

Regards
Norbert
Dmitry Arefiev

Posts: 1,406
Registered: 12/7/03
Re: Recognation of AutoInc field for Firebird 2.5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 24, 2017 11:34 PM   in response to: Norbert Meier in response to: Norbert Meier
On +DX10.1 source base your test application works correctly:
* ID field is recognized as TLargeintField. This is correct because ID is defined as BIGINT and it does not fit into TAutoIncField.
* ID field is setup correctly, so FireDAC automatically refetches new ID value after posting a new record.

If you see different behavior, then please specify your exact RAD Studio version. And I will check what and when was changed in FireDAC in this area.

--
With best regards,
Dmitry
Norbert Meier

Posts: 19
Registered: 11/26/01
Re: Recognation of AutoInc field for Firebird 2.5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 24, 2017 11:53 PM   in response to: Dmitry Arefiev in response to: Dmitry Arefiev
I'm currently using XE6 for that Project..

If I don't set AutoIncFields:

After calling Append:

prjInfTemp1.FieldByName('ID').IsNull is True
prjInfTemp1.FieldByName('ID').AsLArgeInt is 0

Post fires exception: Add record failed: Field 'ID' must have a value

If I set AutoIncFields

After calling Append:

prjInfTemp1.FieldByName('ID').IsNull is False
prjInfTemp1.FieldByName('ID').AsLArgeInt is -1

Post works fine in this case.

PS: The two assert lines regarding "ID" is Null or = -1 fail in the demo app, if I don't set AutoIncFields!

Regards
Norbert
Dmitry Arefiev

Posts: 1,406
Registered: 12/7/03
Re: Recognation of AutoInc field for Firebird 2.5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 25, 2017 2:19 AM   in response to: Norbert Meier in response to: Norbert Meier
That means, that ID field is not recognized as auto-inc field.
There were multiple changes in this area after XE6, so it is not simple to provide patch.
So, setting AutoIncFields is a correct workaround.

--
With best regards,
Dmitry
Norbert Meier

Posts: 19
Registered: 11/26/01
Re: Recognation of AutoInc field for Firebird 2.5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 25, 2017 4:00 AM   in response to: Dmitry Arefiev in response to: Dmitry Arefiev
Thanks Dmitry,

I'll use the workaroung to fix this issue.

Best Regards
Norbert
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02