Subject Re: [IBO] Request with Field Origin
Author Matt Nielsen
I didn't solve the Alias issue, but here is the small change to leave
the property alone if it has a value. I will work on the alias issue
another time if I can. I may not understand your code enough to do
this properly.

____________________________ IBODATASET.PAS __________________
procedure TIBODataset.InitFields;
var
ii, jj: integer;
tmpCol: TIB_Column;
tmpField: TField;
IsOk: boolean;
{$IFDEF IBO_VCL50_OR_GREATER}
tmpKey: TIB_Column;
KeyFndCnt: integer;
{$ENDIF}
begin
{$IFDEF IBO_VCL50_OR_GREATER}
KeyFndCnt := 0;
{$ENDIF}
for ii := 0 to FieldCount - 1 do
begin
tmpField := Fields[ii];
if tmpField.FieldKind = fkData then
begin
jj := tmpField.FieldNo - 1;
if jj >= InternalDataset.Fields.PSQLDA.sqld then
jj := InternalDataset.Fields.PSQLDA.sqld - tmpField.FieldNo;
tmpCol := InternalDataset.Fields.BySQLNo( jj );
IsOk := false;
if tmpField.FieldName <> tmpCol.BDEFieldName then
begin
if AnsiCompareText( tmpField.FieldName, tmpCol.BDEFieldName )
= 0 then
begin
tmpField.FieldName := tmpCol.BDEFieldName;
IsOk := true;
end;
end
else
IsOk := true;

if IsOk then
begin
if DefaultFields or (foDisplayFromIBO in FFieldOptions) then
begin
tmpField.Alignment := tmpCol.Alignment;
tmpField.Required := tmpCol.Required and not
tmpCol.IsDefaulted;
tmpField.DisplayLabel := tmpCol.DisplayLabel;
if tmpField is TDateTimeField then
(tmpField as TDateTimeField).DisplayFormat :=
tmpCol.DisplayFormat
else
if tmpField is TNumericField then
begin
(tmpField as TNumericField).DisplayFormat :=
tmpCol.DisplayFormat;
{$IFDEF VCL130}
end
else
if tmpField is TAggregateField then
begin
(tmpField as TAggregateField).DisplayFormat :=
tmpCol.DisplayFormat;
{$ENDIF}
end;
tmpField.ReadOnly := tmpCol.ReadOnly;
// These two properties are not compatible because one is
characters
// and the other one is pixels.
// tmpField.DisplayWidth := tmpCol.DisplayWidth;
tmpField.EditMask := tmpCol.EditMask;
tmpField.Visible := tmpCol.Visible;
end
else
tmpCol.IsAttributeSet[ IB_REQUIRED ] := tmpField.Required;
{$IFDEF IBO_VCL50_OR_GREATER}
with InternalDataset.KeyFields do
begin
if ( KeyFndCnt < ColumnCount ) and
( GetByName( tmpCol.FieldName, tmpKey )) then
begin
tmpField.ProviderFlags := tmpField.ProviderFlags + [
pfInKey ];
Inc( KeyFndCnt );
end;
end;
if ( tmpCol.RelName <> '' ) and
( tmpCol.SQLName <> '' ) then
// MAN CAELIX 12/22/03 incorrect origin if aliased table don't
overwrite the saved one.
if Trim(tmpField.Origin) = '' then
tmpField.Origin := tmpCol.RelName + '.' + tmpCol.SQLName;
{$ENDIF}
end
else
Assert( false,
'IBDatasetFields.InitFields tmpField.FieldName: ' +
tmpField.FieldName + ' <> tmpCol.BDEFieldName: ' +
tmpCol.BDEFieldName );
end;
end;
if InternalDataset.FieldsIndex.Count > 0 then
for ii := 0 to InternalDataset.Fields.ColumnCount - 1 do
begin
tmpCol := InternalDataset.Fields[ii];
tmpField := FindField( tmpCol.BDEFieldName );
if Assigned( tmpField ) then
tmpField.Index := ii;
end;
end;

__________________________________________________



--- In IBObjects@yahoogroups.com, "Jason Wharton" <jwharton@i...>
wrote:
> I agree this is an area that could use some closer attention.
> Did you make any modifications to the IBO sources to suit this?
> If so, I could probably just merge them in.
> I agree that if there is a value in the ORIGIN property then I
could just
> leave it alone.
>
> Jason Wharton
> www.ibobjects.com
>
> ----- Original Message -----
> From: "Matt Nielsen" <mnielsen@c...>
> To: <IBObjects@yahoogroups.com>
> Sent: Friday, January 02, 2004 11:41 AM
> Subject: [IBO] Request with Field Origin
>
>
> > I've noticed that the new version of IBO now populates the origin
> > under all circumstances. I use this field for the same purpose
that
> > IBO does to store the real tablename.fieldname I then use this for
> > different reasons but mostly for use on grids and column sorting
and
> > building query statemens. The problem is that IBO doesn't
generate
> > the correct origin if you have table aliasing. Meaning if I have
the
> > following SQL:
> >
> > SELECT
> > TABLEA.COLUMNA,
> > ALIASA.COLUMNA AS ALIASA_COLUMNA,
> > ALIASB.COLUMNA AS ALIASB_COLUMNB
> > FROM TABLEA
> > LEFT OUTER JOIN TABLEB ALIASA
> > ON (TABLEA.LINK1 = ALIASA.SEQNO)
> > LEFT OUTER JOIN TABLEB ALIASB
> > ON (TABLEA.LINK2 = ALIASB.SEQNO)
> >
> > Then IBO would generate an origin for the for field
ALIASA_COLUMNA as
> > TABLEB.COLUMNA when it should have generated ALIASA.COLUMNA.
> >
> > A simple fix is that if the origin already has data in it then
don't
> > overwrite it when IBO generates the field.
> >
> > Another solution would be to teach the parser how to deal with
table
> > aliases.
> >
> > Another request would be to have the values of the origin at
design
> > time not just runtime, certainly you would need to prevent it from
> > overwriting values if this was implemented.
> >
> >
> >
> > Thanks,
> >
> > Matt Nielsen
> > Caelix, Inc
> >