Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/ADO    [ Add a report in this area ]  
Report #:  7529   Status: Open
TCustomADODataSet.PSGetDefaultOrder ignores 'Order By' CommandText clause
Project:  Delphi Build #:  4.453
Version:    7.0 Submitted By:   Dave Rowntree
Report Type:  Basic functionality failure Date Reported:  3/5/2004 9:16:35 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   197526
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
An incorrect DEFAULT_ORDER index is created against an ADODataSet/ADOQuery when the CommandText/SQL contains an 'Order By' clause. The 'Order By' clause is ignored.

This is a conciderable problem with MIDAS since the CDS has an incorrect DEFAULT_ORDER index.
Steps to Reproduce:
1. Download and unzip the test case app from Attachments.
2. Open the test case app in D7.
3. Follow the on screen steps.
Workarounds
ADODB.PAS
(**) (* QC#7529 PSGetDefaultOrder ignores CommandText 'order by' clause *)
(* Delphi 6.0 - 7.0 *)
(* Dave Rowntree 05 Mar 2004 *)

  TCustomADODataSet = class(TDataSet, IUnknown, RecordsetEventsVt)
  private
    FRecordsetObject: _Recordset;
.....
    function GetPrepared: Boolean;
    function GetProperties: Properties;
    function GetQueryFromType: string; (**) (* QC#7529 add this function *)
    function GetRecordsetState: TObjectStates;
    function GetRecordStatus: TRecordStatusSet;
    function GetSort: WideString;
    procedure PropertyChanged;
.....

function TCustomADODataSet.PSGetDefaultOrder: TIndexDef;
.....
var
  DefIdx: TIndexDef;
  FreeDefIdx: boolean; (**) (* QC#7529 add this line *)
begin
  DefIdx := nil;
  IndexDefs.Update;
  try
    if IndexName <> '' then
      DefIdx := IndexDefs.Find(IndexName)
    else if IndexFieldNames <> '' then
      DefIdx := IndexDefs.GetIndexForFields(IndexFieldNames, False);
    if Assigned(DefIdx) then
      GetFieldList(nil, DefIdx.Fields);
  except
    DefIdx := nil;
  end;
  FreeDefIdx := Assigned(DefIdx); (**)(* QC#7529 add this line *)
  try (**)(* QC#7529 add this line *)
    if not Assigned(DefIdx) then (**)(* QC#7529 add this line *)
      DefIdx := GetIndexForOrderBy(GetQueryFromType, Self); (**)(* QC#7529 add this line *)
    if Assigned(DefIdx) and not FreeDefIdx then (**)(* QC#7529 add this line *)
      FreeDefIdx := True;                    (**)(* QC#7529 add this line *)
    if not Assigned(DefIdx) then
      DefIdx := GetIdx(ixPrimary);
    if not Assigned(DefIdx) then
      DefIdx := GetIdx(ixUnique);
    if Assigned(DefIdx) then
    begin
      Result := TIndexDef.Create(nil);
      Result.Assign(DefIdx);
    end else
      Result := nil;
  finally                (**)(* QC#7529 add this line *)
    if FreeDefIdx then   (**)(* QC#7529 add this line *)
      DefIdx.Free;       (**)(* QC#7529 add this line *)
  end;                   (**)(* QC#7529 add this line *)
end;
Attachment
7529.zip
Comments

Dave Rowntree at 3/16/2004 11:37:02 AM -
I updated the workaround. It could have caused a memory leak as it was.

Server Response from: ETNACODE01