Page 1 of 1

How can I capture the SQL code of a field ?

Posted: Thu 27 Oct 2016 02:20
by luapfr
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

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

Posted: Thu 27 Oct 2016 11:30
by ViktorV
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.

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

Posted: Thu 27 Oct 2016 11:35
by luapfr
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?

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

Posted: Thu 27 Oct 2016 13:20
by ViktorV
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.