Recent

Author Topic: TSqlQuery with Firebird 3 "generated as identity" columns?  (Read 3025 times)

dsiders

  • Hero Member
  • *****
  • Posts: 1084
TSqlQuery with Firebird 3 "generated as identity" columns?
« on: December 26, 2017, 01:02:43 am »
I been trying to get TSqlQuery in Lazarus 1.8 to work with Firebird 3 tables that contain
"generated by default as identity" columns. InsertSql statements always raise an exception about the missing value for the required ID field. Editing the FieldDef to make it not required and read-only hasn't helped.

Does this FB3 feature work in sqldb for 1.8?
« Last Edit: December 26, 2017, 01:07:55 am by dsiders »
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

sash

  • Sr. Member
  • ****
  • Posts: 366
Re: TSqlQuery with Firebird 3 "generated as identity" columns?
« Reply #1 on: December 26, 2017, 03:39:22 pm »
Well, I don't know what is a current state of development, but you could use a workaround: for your SQLQuery.Sequence set FieldName and SequenceName accordingly.

SequenceName should be set to the internal generator name for your field: something like RDB$123.
Exact name could be retrieved with query:

Code: SQL  [Select][+][-]
  1. SELECT rdb$generator_name FROM rdb$relation_fields
  2. WHERE rdb$relation_name = 'YOUR_TABLE' AND rdb$field_name = 'YOUR_ID_FIELD'
  3.  

Please take note, that internal generator name may differ on another database instance.
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

dsiders

  • Hero Member
  • *****
  • Posts: 1084
Re: TSqlQuery with Firebird 3 "generated as identity" columns?
« Reply #2 on: December 26, 2017, 05:59:12 pm »
Well, I don't know what is a current state of development, but you could use a workaround: for your SQLQuery.Sequence set FieldName and SequenceName accordingly.

SequenceName should be set to the internal generator name for your field: something like RDB$123.
Exact name could be retrieved with query:

Code: SQL  [Select][+][-]
  1. SELECT rdb$generator_name FROM rdb$relation_fields
  2. WHERE rdb$relation_name = 'YOUR_TABLE' AND rdb$field_name = 'YOUR_ID_FIELD'
  3.  

Please take note, that internal generator name may differ on another database instance.

Thanks sash. I'm getting ready to try your suggestion. But it sure would be nice if the fielddefs had an ftIdentity data type that triggered this automatically. Breaking changes... :)
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

talorigomat

  • Jr. Member
  • **
  • Posts: 96
Re: TSqlQuery with Firebird 3 "generated as identity" columns?
« Reply #3 on: December 27, 2017, 01:07:32 pm »
Lets say your identity field is named widgetid
then issuing the following command before issuing the applyupdates command should resolve the problem

Code: Pascal  [Select][+][-]
  1. SQLQuery1.FieldByName('widgetid').Required:=False
Lazarus 1.8.0Rc4, Windows 10

 

TinyPortal © 2005-2018