Recent

Author Topic: Aggregate functions  (Read 1951 times)

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Aggregate functions
« on: May 10, 2020, 06:36:44 pm »
Hi All,
a simple question (and, I hope, an easy answer).

Can I use aggregate functions (SUM) in an RxMemoryData database? If so how?

Thanks in advance.

Thaddy

  • Hero Member
  • *****
  • Posts: 17153
  • Ceterum censeo Trump esse delendam
Re: Aggregate functions
« Reply #1 on: May 12, 2020, 07:16:09 am »
One way is simply to iterate the records and sum the fields in Pascal code.
Btw: this is a really old component.
A more modern one would be Sqlite which can be configured as an in-memory database and fully supports SQL.
FreePascal comes with two different versions. TSqlite3, and an Sqlite connector for TSqlQuery. ( https://wiki.freepascal.org/SQLdb_Package )
How to is here https://sqlite.org/inmemorydb.html This works with both avalable versions. Since I discovered that, I use it all the time.
« Last Edit: May 12, 2020, 07:45:37 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

eljo

  • Sr. Member
  • ****
  • Posts: 468
Re: Aggregate functions
« Reply #2 on: May 12, 2020, 07:36:21 am »
Hi All,
a simple question (and, I hope, an easy answer).

Can I use aggregate functions (SUM) in an RxMemoryData database? If so how?

Thanks in advance.
I have no idea what rxMemoryData is but I thought that SQLDB supported aggregate fields on datasets but you would have to use static fields instead of dynamic ones.

Thaddy

  • Hero Member
  • *****
  • Posts: 17153
  • Ceterum censeo Trump esse delendam
Re: Aggregate functions
« Reply #3 on: May 12, 2020, 08:23:35 am »
[I have no idea what rxMemoryData is but I thought that SQLDB supported aggregate fields on datasets but you would have to use static fields instead of dynamic ones.
Yes, but through the underlying database. E.g. the second Sqlite example I suggested can provide the in-memory database that is required using SqlDb (TSqlQuery).
TBufDataset has also good filtering options, but no aggregation without writing some pascal code. Zeoslib can do the same.
There is also a very lightweight in memory SQL component written by Jan Verhoeven. But Sqlite in-memory has simply my preference because it is full-featured and very fast.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Aggregate functions
« Reply #4 on: May 12, 2020, 01:48:32 pm »
Thanks guys for yor feedback. I'll give SQLlite a look.
I know MariaDB / MySQL so it shouldn't be a problem. I didn't want to use a SQL DB, I thought it would be overkill. Thanks anyway.

 

TinyPortal © 2005-2018