How can I capture the SQL code of a field ?

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
luapfr
Posts: 37
Joined: Thu 11 Apr 2013 13:11

How can I capture the SQL code of a field ?

Post by luapfr » Thu 27 Oct 2016 02:20

Hello I am giving a studied in your library and appears to be very powerful.

How do I know the SQL command that generated particular field after executing a query ?

But I'm not able to use.
I use Firebird 2.5

I am looking to pass the name of the field and return all the SQL command using to generate the field.

If I have the following field:

Code: Select all

Coalesce(Case When (Trim(NF.N_CF) <> '') Then  NF.N_CF || ' ' End, '') 
 || 
Coalesce(Case When (Trim(NF.N_NFM) <> '') Then  NF.N_NFM || ' ' End, '') 
As N_CUPOM, 
If I pass this field "N_CUPOM"
I would like to return me ::

Code: Select all

Coalesce (Case When (Trim (NF.N_CF) <> '') Then NF.N_CF || '' End '')
  ||
Coalesce (Case When (Trim (NF.N_NFM) <> '') Then NF.N_NFM || '' End '')
How can I do this ?

Grateful

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: How can I capture the SQL code of a field ?

Post by ViktorV » Thu 27 Oct 2016 11:30

Unfortunately, this functionality in IBDAC is not supported, as Firebird does not allow to receive a part of the SQL statement used to generate a specific field.

luapfr
Posts: 37
Joined: Thu 11 Apr 2013 13:11

Re: How can I capture the SQL code of a field ?

Post by luapfr » Thu 27 Oct 2016 11:35

I would have to do some kind of pass to get the SQL command would be something near to it ?

Code: Select all

TCRFieldDesc(TDBAccessUtils.GetIRecordSet(UniQuery1).Fields[i]).TableInfo.TableAlias
I've looked on the internet something like SQL Parse more did not find anything to do that, it's been two days that I search on GOOGLE without success.

You would not have any idea or suggestion on how I can do this?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: How can I capture the SQL code of a field ?

Post by ViktorV » Thu 27 Oct 2016 13:20

As we have already mentioned, Firebird does not allow to receive a part of the SQL statement used to generate a specific field.
For the fields such as N_CUPOM (e.g., generated using the functions and so on), Firebird does not return any information for the value of the property TableAlias, so you won't be able to use this approach.
To solve your issue you can implement the parsing of the SQL query by yourself.

Post Reply