Field Alias - Origin field

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
acgubamg
Posts: 5
Joined: Tue 13 May 2014 02:57

Field Alias - Origin field

Post by acgubamg » Tue 13 May 2014 03:15

When I run sql:

select CADPRO.CODIGO_PRO,
CADPRO.DESCRICAO_PRO,
F.NOME_CLI "Razão Social do Fornecedor",
C.NOME_CLI "Razão Social do Cliente"
from CADPRO
inner join CADCLI F on (F.CODCLI = CADPRO.FORNECEDOR_PRO)
inner join CADCLI C on (C.CODCLI = CADPRO.CLIENTE_PRO)

The field origin doesnt work...
see the TFieldDefs

object UniQuery1CODIGO_PRO: TIntegerField
FieldName = 'CODIGO_PRO'
Origin = 'CADPRO.CODIGO_PRO'
Required = True
end
object UniQuery1DESCRICAO_PRO: TStringField
FieldName = 'DESCRICAO_PRO'
Origin = 'CADPRO.DESCRICAO_PRO'
Size = 50
end
object UniQuery1RazãoSocialdoFornecedor: TStringField
FieldName = 'Raz'#227'o Social do Fornecedor'
Origin = 'CADCLI.NOME_CLI' <<<<<<<<<<<<<<<<<<Wrong here
ReadOnly = True
Size = 50
end
object UniQuery1RazãoSocialdoCliente: TStringField
FieldName = 'Raz'#227'o Social do Cliente'
Origin = 'CADCLI.NOME_CLI' <<<<<<<<<<<<<<<<<<Wrong here
ReadOnly = True
Size = 50
end

why its happens?

PS: Firebird - Unidac

PavloP
Devart Team
Posts: 149
Joined: Fri 24 Jan 2014 12:33

Re: Field Alias - Origin field

Post by PavloP » Wed 14 May 2014 10:56

The Origin property in your sample contains correct information - it specifies the field name in the database table.
You can find more details about the Origin property in the Embarcadero documentation:
http://docwiki.embarcadero.com/Librarie ... eld.Origin

acgubamg
Posts: 5
Joined: Tue 13 May 2014 02:57

Re: Field Alias - Origin field

Post by acgubamg » Sat 17 May 2014 03:48

then when I do the filter in sql:

     sFieldName: = 'Razão Social do Cliente';

     scampo: = TUniQuery (DSC) FindField (sFieldName).Origin; => result: CADCLI.NOME_CLI


sWhere: = '((UPPER (' scampo + + ') LIKE' + QuotedStr (iif (CheckParte.Checked, '%','') + Trim (EditNome.Text) + '%') + ')';

For scampo have the table name of "CADCLI.NOME_CLI" and not "C.NOME_CLI" as a result will generate a wrong filter in sql.

Note:
in help in the "table name" (CUSTOMER) does not have alias name...
this case, the sql would not wrong.


PavloP
Devart Team
Posts: 149
Joined: Fri 24 Jan 2014 12:33

Re: Field Alias - Origin field

Post by PavloP » Tue 20 May 2014 09:49

To retrieve a table alias for a certain dataset field, use the TableInfo property of the TCRFieldDesc class:

Code: Select all

TCRFieldDesc(TDBAccessUtils.GetIRecordSet(UniQuery1).Fields[i]).TableInfo.TableAlias
The TCRFieldDesc class is defined in the CRAccess module, the TDBAccessUtils class is defined in the DBAccess module.

The problem is that Firebird doesn't return information about aliases, and when a table is used in a query with several aliases, then the TableAlias property will contain the name of the first alias assigned to this table.

acgubamg
Posts: 5
Joined: Tue 13 May 2014 02:57

Re: Field Alias - Origin field

Post by acgubamg » Thu 22 May 2014 04:35

hello:

TCRFieldDesc(TDBAccessUtils.GetIRecordSet(UniQuery1).Fields).TableInfo.TableAlias

I tried using this way, but, TableAlias always is empty.

The problem could be in: Unit IBCClassesUni

on procedure:

procedure FillTablesAliases;

and

procedure DescribeDefineFieldDesc(Field: TIBCFieldDesc; SQLVAR: TSQLVARAccessor; FieldNo: integer);

Note that, always set TableAlias to a empty string.
----
"SQLVAR" returns wrong because when you repeat a table in sql, does not add "TableInfo"

the source code:

if FldTableName <> '' then begin
TableInfo := FTablesInfo.FindByName(FldTableName);
if TableInfo = nil then // here, "cadcli" adds only once
begin
TableInfo := FTablesInfo.Add;
TableInfo.TableName := FldTableName;
TableInfo.TableAlias := '';
end;
Field.TableInfo := TableInfo;
end
else
Field.TableInfo := nil;

----------------------------------
Platform: FB 2.5.2
Delphi XE5.

acgubamg
Posts: 5
Joined: Tue 13 May 2014 02:57

Re: Field Alias - Origin field

Post by acgubamg » Thu 22 May 2014 06:01

PavloP

Its a possible solution ?

https://golden-temp.googlecode.com/svn/ ... ataSet.pas

find by function TFIBCustomDataSet.GetFieldOrigin(Fld:TField):string;

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: Field Alias - Origin field

Post by ZEuS » Thu 22 May 2014 08:23

We are investigating the possibility of implementing such functionality in one of the next UniDAC builds.
As soon as we implement the functionality, we can send you a night build including the fix. We will inform you when we have any results.

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: Field Alias - Origin field

Post by ZEuS » Mon 26 May 2014 06:43

We have implemented the functionality. The fix will be included in the next UniDAC build.
For now, we can send you a night build including the fix. Please send an email to eugeniyz*devart*com, in which specify your license number (if you are a registered user).

Post Reply