Recent

Author Topic: [SOLVED] Record sorting SQLite  (Read 1326 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 590
[SOLVED] Record sorting SQLite
« on: November 18, 2023, 05:18:04 pm »
Hello, is it possible to sort records in such a way that the database remembers the sorting?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.SpeedButton5Click(Sender: TObject);
  2. begin
  3.    ZQuery1.SQL.Text := 'SELECT * FROM users ORDER BY Name ASC';
  4.    ZQuery1.ExecSQL;
  5.    ZQuery1.Open;
  6. end;
  7.  

« Last Edit: November 23, 2023, 11:25:39 am by Pe3s »

BSaidus

  • Hero Member
  • *****
  • Posts: 607
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Record sorting SQLite
« Reply #1 on: November 18, 2023, 05:45:47 pm »
Short answer: NO
Hello, is it possible to sort records in such a way that the database remembers the sorting?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.SpeedButton5Click(Sender: TObject);
  2. begin
  3.    ZQuery1.SQL.Text := 'SELECT * FROM users ORDER BY Name ASC';
  4.    // Use ExecSQL if you need to Insert, Update, Delete a record ( in this case you do not need it )
  5.    // ZQuery1.ExecSQL;
  6.    ZQuery1.Open;
  7. end;
  8.  


lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Pe3s

  • Hero Member
  • *****
  • Posts: 590
Re: Record sorting SQLite
« Reply #2 on: November 19, 2023, 07:19:38 pm »
Is there no way to do it in alphabetical order?

dsiders

  • Hero Member
  • *****
  • Posts: 1327
Re: Record sorting SQLite
« Reply #3 on: November 19, 2023, 07:50:02 pm »
Is there no way to do it in alphabetical order?

'order by NAME asc' is alphabetic order. IF you want case-insensitive alphabetic order use the 'COLLATE NOCASE clause.

Code: MySQL  [Select][+][-]
  1. SELECT * FROM users ORDER BY Name COLLATE NOCASE ASC

You can apply collate to the schema too.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

Pe3s

  • Hero Member
  • *****
  • Posts: 590
Re: Record sorting SQLite
« Reply #4 on: November 23, 2023, 11:25:20 am »
Thank you :)

 

TinyPortal © 2005-2018