Recent

Author Topic: SQLQuery.Last  (Read 10171 times)

TRNelson

  • Jr. Member
  • **
  • Posts: 64
Re: SQLQuery.Last
« Reply #15 on: February 09, 2016, 01:36:35 am »
You said you don't have a DBGrid (or do you??) so you could just work with SQL statements to get the correct record.
I am using DBGrid and it works well for displaying several records.  The user can navigate through the table using arrows keys or by pressing some coded buttons.  The current record is displayed separately.  It all works rather well.   I use SQLQuery.Locate to do the searching.  The SQLQuery.Last is a red herring and really has a very limited use for this app and will be dropped.

Is Locate nothing more than read: a record, check for match, if matched end otherwise keeping reading and comparing on the client side or does this happen on the server side? 

You guys have a lot of patience and I really appreciate the help and insight.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: SQLQuery.Last
« Reply #16 on: February 09, 2016, 05:21:36 am »
Locate works all on the client-side and is essentially a next/check kind a thing. In your case it's better to adjust the sql with the filter the user desires and not use locate for this. But instead of changing the sql each time you could also look into Serverfilter and Serverfiltered. Don't look at Filter and Filtered because that is client-side too. But ServerFilter will adjust the sql internally and close and open the dataset automatically.

Also, if you want the exact count of a current dataset you can't do .last and usr .recordcount. Best is to use a small separate sql with SELECT COUNT(ID) FROM TABLE WHERE xxxx to get the exact count. It might be useful for the user to know how many records there are and in this case (s)he doesn't need to do ctrl-end on the grid to jump to the end to see that. (So you also might want to catch ctrl-end in the grid because that will try to go to the end which will result in a showdown when ask the records are retrieved again.)

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: SQLQuery.Last
« Reply #17 on: February 09, 2016, 09:11:10 am »
@rvk is right, in this particular case you don't need a stored procedure, although you can use one just for the sake of exercise.
Guys if it's firebird, what about this query:
Code: Pascal  [Select][+][-]
  1. select * from TABLENAME where id in (select max(id) from TABLENAME)

PS: http://www.firebirdsql.org/refdocs/langrefupd21-ddl-procedure.html
Is nice. But there are still databases who are not indexed with an id.

Is TSQLQuery.last not relative to an index?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: SQLQuery.Last
« Reply #18 on: February 09, 2016, 10:35:06 am »
Is TSQLQuery.last not relative to an index?
No, it is relative to the order in which the server presents the dataset. That could be according to an actual index but it not necessary. You could do an "ORDER BY NAME" without having an index on the field NAME. And even if you just do an SELECT * FROM TABLE without an ORDER BY, the server presents the dataset in an unspecified order. TSQLQuery.Last would just jump to the last record in that dataset.

 

TinyPortal © 2005-2018