Recent

Author Topic: Sorting tsqlquery with indexes working example(Yes it works now)  (Read 15132 times)

antoniocangiano76

  • New member
  • *
  • Posts: 5
Re: Sorting tsqlquery with indexes working example(Yes it works now)
« Reply #15 on: October 14, 2021, 09:18:15 pm »
Quote
I have used just this code in my application, compiled with Lazarus 2.0.4 for Windows.
It was nice that when column callid is once sorted, newly loaded data becomes sorted, too.
It work fine for a couple of years, until I have upgraded Lazarus to 2.0.10.
Now it works the very first time only, attempt to load new data causes exception
DBQuery1: Index 'ASC_callid' not found.
I didn't investigate how the indexes work. Maybe there is quite a simple idea how to bring this code back to life?

Lazarus 2.0.12 FPC 3.2.0 Win10 21H1 64bit
Same problem...Here is my steps
1) I set index on first column (OK) 
2) Then set a filter on query q1 with a Tedit with this code :

Code: Pascal  [Select][+][-]
  1. procedure Tf_param.te_filtroChange(Sender: TObject);
  2. begin
  3.    if Trim(te_filtro.Text) <> '' then
  4.   begin
  5.     if not q1.Filtered then q1.Filtered := True;
  6.     q1.Refresh;
  7.   end else
  8.     q1.Filtered := False;
  9. end;      

and ...

Code: Pascal  [Select][+][-]
  1. procedure Tf_param.q1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
  2. var
  3.   i,k: integer;
  4. begin
  5.   for i := 0 to dbg1.Columns.Count -1 do begin
  6.     if dbg1.Columns[i].Visible then begin;
  7.        Accept := Pos( iif( togglebox1.checked,UpperCase(te_filtro.Text),te_filtro.Text ),
  8.                       iif( togglebox1.checked,UpperCase(dbg1.Columns[i].Field.AsString),
  9.                       dbg1.Columns[i].Field.AsString) ) > 0;
  10.        if Accept then exit;
  11.     end;
  12.   end;
  13.   //   if Accept = False then Accept := Pos(UpperCase(te_filtro.Text), UpperCase(DataSet.FieldByName('DESC2').AsString)) > 0;
  14. end;  

3) When I insert first char in Tedit, I got "q1 _ Index 'ASC_DESC' not found
4) Error occours in Tedit onchange at
Code: Pascal  [Select][+][-]
  1. q1.Refresh;


Any ideas?
Thanks

wp

  • Hero Member
  • *****
  • Posts: 9021
Re: Sorting tsqlquery with indexes working example(Yes it works now)
« Reply #16 on: October 14, 2021, 11:28:49 pm »
Your description does not provide enough information. What kind of query is q1? The title of the thread mentions sqlquery, but I cannot believe this because then you'd filter the query result by the sql clause, not by the OnFilterRecord event.

Ideally you should provide a simple small compilable project which shows the error. Remove everything from your project which is not related to this issue and check that the bug still exists, then upload the .pas, .lfm, .lpi, .lpr and database file, all packed into a shared zip.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018