Subject Re: IndexFieldName with descending order
Author mayerherbert
Hi Jason - THX for answer :)

Sorry but changing to indexname is definitly too much work for our existing project. Too much uses of the descending ordering via the IndexFieldNames.
...The other problem is that in the current state IBO "deform" The IndexFieldNames as soon as you open the unit with such tables in the Delphi IDE. A IndexFieldName Property 'MyField1 desc;MyField2 desc' goes to 'MyField1;desc;MyField2;desc' as soon you open the unit with such TIBOTable's in the IDE. And with that automatic disformed code it gives you an error by next runtime. ...so no acceptable state atm.

We made a temporary fix in the the Procedure ExtractFieldName located in the IB_Parse.pas to handle spaces as it was before.
I suggest you are using that basic procedure in a lot of internal cases, so please can you take a look on it if theses changes are OK? (see the {mrchange} marker)

Tank you for your time and help
best regards

// ---------------------------------------------------------------
function ExtractFieldName( const FieldNames: ansistring;
var Pos: integer ): ansistring;
var
ii: Integer;
tmpL: integer;
Lit: boolean;
SQ1: integer;
SQ2: integer;
procedure IncPos( SkipSpaces: boolean );
begin
Inc( ii );
while (not Lit) and
(ii <= tmpL) and
(FieldNames[ii] = ' ') and
SkipSpaces do
Inc( ii );
end;
begin
if Pos = ParseLineInvalid then
Pos := 1;
Lit := false;
SQ1 := 0;
SQ2 := 0;
tmpL := Length(FieldNames);
ii := Pos - 1;
IncPos( true ); // Gobble up leading spaces since we will use space as a terminator now.
while (ii <= tmpL) do
begin
case FieldNames[ii] of
'"': Lit := not Lit;
'[': if not Lit then Inc( SQ1 );
']': if not Lit then Dec( SQ1 );
'{': if not Lit then Inc( SQ2 );
'}': if not Lit then Dec( SQ2 );
{' ', mrchange 20100112 }',',';',#10,#13: if ( not Lit ) and ( SQ1 + SQ2 = 0 ) then Break;
end;
IncPos( false );
end;
Lit := false;
Result := Trim( Copy( FieldNames, Pos, ii - Pos ));
if (ii <= tmpL) and (FieldNames[ii] in [ {' ', mrchange 20100112 } ',', ';' ] ) then IncPos( true );
if (ii <= tmpL) and (FieldNames[ii] = #13 ) then IncPos( true );
if (ii <= tmpL) and (FieldNames[ii] = #10 ) then IncPos( true );
Pos := ii;
end;
// ---------------------------------------------------------------




--- In IBObjects@yahoogroups.com, "Jason Wharton" <supportlist@...> wrote:
>
> > With the old 4.8 IBO the indexfieldnames can set to
> > MyTable.indexfieldname := 'MYFIELD desc'; and it worked fine for a
> > descending order.
> >
> > But now with the 4.9 the Function IB_PARSE.ExtractFieldName was changed
> > that the space out of a quoted text is now a indicator for a terminater.
> >
> > So - OK, I changed the IndexFieldname and quoted it into
> > MyTable.indexfieldname := '"MYFIELD desc"';
> >
> > But the SQL the IBO-Parser send to the DB-Server leave the quotes, so the
> > sql is
> > select * from MyTable order by "MYFIELD desc"
> >
> > But such quoted orders are ignored by the SQL-Server. (as you can also
> > quickly check wit a console like eg. ibexpert) - I suggest it do not
> > interprete quoted stuff as fields or commands or smth else.
> >
> > ---------
> > So simply Question: "From Version 4.9 How to set the IndexFieldNames
> > Property of a TIBOTable to make a descending order ?"
> > ---------
>
> You can create a descending index if you don't already have one and then set
> the IndexName to that index and it should work the way you want it to.
>
> Let me know.
>
> Jason Wharton
>