Recent

Author Topic: Getting Row Number From a SQLite query  (Read 2298 times)

Ericktux

  • Sr. Member
  • ****
  • Posts: 352
Re: Getting Row Number From a SQLite query
« Reply #15 on: July 13, 2024, 02:12:35 am »
In a dbgrid loaded with sqlite I do it like this:

Code: Pascal  [Select][+][-]
  1.   ShowMessage(inttostr(DBGrid1.DataSource.DataSet.RecNo));    // ROW
  2.   ShowMessage(inttostr(DBGrid1.SelectedIndex));    //   COL

from the selected row get the value of the third column:

Code: Pascal  [Select][+][-]
  1. ShowMessage(DBGrid1.DataSource.DataSet.Fields[2].Value);

I hope it helps you friend, greetings  :)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 610
    • Double Dummy Solver - free download
Re: Getting Row Number From a SQLite query
« Reply #16 on: July 13, 2024, 02:29:16 am »
Thanks...I'll give it a try. I'm pretty sure the DBGrid works a lot faster than a DrawGrid that I've been using.
Lazarus 3.6 FPC 3.2.2 x86_64-win64-win32/win64

jcmontherock

  • Sr. Member
  • ****
  • Posts: 272
Re: Getting Row Number From a SQLite query
« Reply #17 on: July 13, 2024, 10:56:38 am »
In SQLite there is a hidden field named "rowid" which can be used in sql. Ex:
Code: Pascal  [Select][+][-]
  1. select rowid, * from table...
.
It's created at table creation. So if you delete a row in the table rowid is not updated. If you want to have the real rowid in the table you have 2 solutions:
1) Recreate the table.
2) Execute a complex script to update it. See: https://stackoverflow.com/questions/1601697/sqlite-reset-primary-key-field
The best is perhaps to define a field with the autoincrement property.
Windows 11 UTF8-64 - Lazarus 4RC1-64 - FPC 3.2.2

 

TinyPortal © 2005-2018