Page 1 of 1

Field Alias - Origin field

Posted: Tue 13 May 2014 03:15
by acgubamg
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

Re: Field Alias - Origin field

Posted: Wed 14 May 2014 10:56
by PavloP
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

Re: Field Alias - Origin field

Posted: Sat 17 May 2014 03:48
by acgubamg
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.

Re: Field Alias - Origin field

Posted: Mon 19 May 2014 01:02
by acgubamg

Re: Field Alias - Origin field

Posted: Tue 20 May 2014 09:49
by PavloP
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.

Re: Field Alias - Origin field

Posted: Thu 22 May 2014 04:35
by acgubamg
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.

Re: Field Alias - Origin field

Posted: Thu 22 May 2014 06:01
by acgubamg
PavloP

Its a possible solution ?

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

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

Re: Field Alias - Origin field

Posted: Thu 22 May 2014 08:23
by ZEuS
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.

Re: Field Alias - Origin field

Posted: Mon 26 May 2014 06:43
by ZEuS
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).