Recent

Author Topic: [SOLVED] RecordCount not working - SQLite3  (Read 1509 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 423
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] RecordCount not working - SQLite3
« on: June 20, 2025, 02:53:51 pm »
Could anyone tell me why this isn't work for reporting the total number of clients in the Clients table in a SQLite3 Database?

Code: Pascal  [Select][+][-]
  1. procedure TFrmClientsMain.QryClientsAfterPost(DataSet: TDataSet);
  2. begin
  3.   EditTTLClients.ReadOnly:= False;
  4.   IntRecCount:= DSrcClients.DataSet.RecordCount;
  5.   EditTTLClients.Text:= IntToStr(IntRecCount); //-> Record total Clients...
  6.   EditTTLClients.ReadOnly:= True;
  7.   BitBtnSave.Enabled:= False;
  8.   BitBtnCancel.Enabled:= False;
  9. end;
  10.  
« Last Edit: June 21, 2025, 07:58:30 pm by 1HuntnMan »

n7800

  • Hero Member
  • *****
  • Posts: 595
  • Lazarus IDE contributor
    • GitLab profile
Re: RecordCount not working - SQLite3
« Reply #1 on: June 20, 2025, 03:02:26 pm »
Perhaps this link will help you.

Thaddy

  • Hero Member
  • *****
  • Posts: 18726
  • To Europe: simply sell USA bonds: dollar collapses
Re: RecordCount not working - SQLite3
« Reply #2 on: June 20, 2025, 04:07:13 pm »
RecordCount is not really a concept that fits well with sql databases, but you can query the database:
Code: SQL  [Select][+][-]
  1. SELECT COUNT(*) FROM your_table_name;
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

CharlyTango

  • Full Member
  • ***
  • Posts: 177
Re: RecordCount not working - SQLite3
« Reply #3 on: June 20, 2025, 09:43:24 pm »
If only a few data records are affected, RecordCount() after a Last() will suffice. If you want to be sure (and for larger amounts of counted records), then ask the SQL server as @Thaddy suggested.

A TDataset is not a DBF table  8-)
Lazarus stable, Win32/64

Thaddy

  • Hero Member
  • *****
  • Posts: 18726
  • To Europe: simply sell USA bonds: dollar collapses
Re: RecordCount not working - SQLite3
« Reply #4 on: June 21, 2025, 07:03:38 am »
In this case the server can also mean Sqlite3, of course.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 423
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: RecordCount not working - SQLite3
« Reply #5 on: June 21, 2025, 07:57:58 pm »
Okay, thanks all. That's from my ole TDbf thinking.

What's the different between a Duck?
     ... One of it's legs are both the same!

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 423
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: [SOLVED] RecordCount not working - SQLite3
« Reply #6 on: June 22, 2025, 05:10:04 pm »
Just feedback what I did:

1. Created a private procedure: UpdateTTLClients
 
Code: Pascal  [Select][+][-]
  1.     procedure UpdateTTLClients;
  2.     begin
  3.        if QryTTLClients.Active then QryTTLClient.Close;
  4.        QryTTLClients.SQL.Text:= 'SELECT COUNT(*) AS TTL FROM CLIENTS;
  5.       QryTTLClients.Open;
  6.       EditTTLCntks.ReadOnly:= False;
  7.       EditTTLCntks.Text:= QryTTLClients.FieldByName('TTL').AsString;
  8.       EditTTLCntks.ReadOnly:= True;
  9.    end;
  10.  
2. Added an extra Query component just for running the query separate from the main QryClients and called it QryTTLClients
3. Of course, need to add in your Form Create: QryTTLClients.Database:= ConnectClients; and QryTTLClients.Transaction:= TransClients
4. Then in your QryClientsAfterDelete and AfterPost just run UpdateTTLClients.

It works ...

 

TinyPortal © 2005-2018