Ticket DQ10623
Visible to All Users

SQL 2003 Date Time format

created 19 years ago

I wish to use the filter text in a SQL query, however the database is NexusDB and it requires SQL 2003 syntax. Basically I need the filter text to be formatted as follows
WHERE
(sourceDate = DATE '2006-03-14') OR
(sourceTime = TIME '08:00:34') OR
(sourceGuid = GUID '{02D72D58-4BB1-4323-AD3C-6B56C4953903}'
i.e The prefix DATE,TIME, GUID etc is where my problem lies. The OnFilterFormatFilterTextValue is limited in that it's difficult to determine which column and dataType is calling the handler. The DateTimeFormat property also does not help for obvious reasons.
I'm sure I'm not the first to ask this question, but have been unable to find any help in the knowledge base, help etc.
Thanks in advance

Comments (3)
DevExpress Support Team 19 years ago

    Hi!
    Regarding your task, it cannot be implemented by simple View filtering operations, sorry. To provide this task, you can use the DataController's Filter.OnBeforeChange event handler and its AFilterText and ADataSet parameters. I suggest that your review the Grid's "TcxDBDataFilterCriteria.OnBeforeChange" help topic and our knowledge base article "How to determine if a filter is active when the Filter.OnBeforeChange or Filter.OnChanged event is fired" at http://www.devexpress.com/kbA962. if you determine the column's and its filtering values used to create filter criteria, you need to process the DataController's Filter.Root property. In the Filter.OnBeforeChange event handler in can be accessed via the Sender parameter. You need to iterate the Sender.Root's items and verify whether the item is a TcxFilterCriteriaItem class or it is another items list. Using TcxFilterCriteriaItem's properties, you can obtain the columns and its values used to create the FilterText (please review the ExpressQuantumGrid's "TcxFilterCriteriaItemList Object" and "TcxFilterCriteriaItem Object" help topics). The sample code below shows this idea.
    procedure TForm1.cxGrid1DBTableView1DataControllerFilterBeforeChange(
      Sender: TcxDBDataFilterCriteria; ADataSet: TDataSet;
      const AFilterText: String);
    var
      I: integer;
      AColumn: TcxGridDBColumn;
      AValue: Variant;
    begin
      with Sender.Root do
      begin
         for I := 0 to Count - 1 do
         if not Items[i].IsItemList then
         begin
          AValue := TcxFilterCriteriaItem(Items[I]).Value;
          AColumn := TcxGridDBColumn(TcxFilterCriteriaItem(Items[I]).ItemLink as TObject);
          …
         end
         else
          begin
           //In this case current item is the item's ItemList
           // You need to use a procedure to iterate the FilterCriteriaItemList with its lists and items as shown above for the Root
           …
           end;
      end;
    end;
    Thanks.

    D D
    Dennis Esmonde-White 19 years ago

      Hi, Thanks for your help.
      I had already reached the point of doing it the way you suggest, but it's just too complicated for such a simple task. I modified your code, which I hate doing, but had no choice. The mod is as follows:
      Unit cxDBData.pas
      type
       TcxDBDataFilterFormatFilterItemEvent = procedure(Sender: TcxFilterCriteriaItem;
         const AValue: Variant; var ADisplayValue: string) of object;

       TcxDBDataFilterCriteria = class(TcxDataFilterCriteria)
       private
         FOnFormatFilterItem: TcxDBDataFilterFormatFilterItemEvent;
       published
         property OnFormatFilterItem: TcxDBDataFilterFormatFilterItemEvent read FOnFormatFilterItem write FOnFormatFilterItem;

      procedure TcxDBDataFilterCriteria.FormatFilterTextValue(AItem: TcxFilterCriteriaItem;
       const AValue: Variant; var ADisplayValue: string);
      begin
       if Assigned(FOnFormatFilterTextValue) then
         FOnFormatFilterTextValue(Self, AValue, ADisplayValue);
       if Assigned(FOnFormatFilterItem) then
         FOnFormatFilterItem(AItem,AValue,ADisplayValue);
      end;
      I am now able to implement a much more elegant solution as follow:
      procedure TMainForm.OnFormatFilterItem(Sender: TcxFilterCriteriaItem; const AValue: Variant; var ADisplayValue: string);
      var
         vColumn: TcxGridDBColumn;
      begin
         vColumn := TcxGridDBColumn(Sender.ItemLink);
         case vColumn.DataBinding.Field.DataType of
         ftDate : ADisplayValue := 'DATE '+ADisplayValue;
         ftTime : ADisplayValue := 'TIME '''+TimeToStr(AValue)+'''';
         ftGuid : ADisplayValue := 'GUID '+ADisplayValue;
         end;
      end;
      As you can see I have added a new published event handler, that implements TcxFilterCriteriaItem instead of the near useless TcxDBDataFilterCriteria object
      as per the OnFilterFormatFilterTextValue method.
      Please consider adding/improving this small bit of code (took me 5 min to do). I am sure you will agree the flexibility is hugely improved.
      Incidentally changing TcxFilterCriteriaItem.Value and TcxFilterCriteriaItem.DisplayValue from inside the OnFilterBeforeChange handler appears to have no affect on the FilterText property.
      Thamks

      DevExpress Support Team 19 years ago

        Hi!
        Thank you for sharing your solution with us. Indeed, this is a very smart approach. We have added your request in our wish list. You can track it here: http://www.devexpress.com/issue=AS4341
        Thanks.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.