Recent

Author Topic: Dataset SQL  (Read 1916 times)

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Dataset SQL
« on: June 03, 2020, 11:16:00 am »
Hi All,

I have DB (RxMemoryDataset). I would like to perform some SQL commands on the dataset. Is this possible? Or how would I go about doing something like UPDATE .... SET X = Y WHERE IDX  = Z?

Thanks for your help / advice.

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Dataset SQL
« Reply #1 on: June 03, 2020, 11:40:12 am »
As far as I can see in the source code, TRxMemory Dataset does not support SQL. To my knowledge, the only memory-dataset with SQL support is TZMQueryDataset in the ZMSQL package (available via OPM).

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Dataset SQL
« Reply #2 on: June 03, 2020, 01:56:52 pm »
I've had a look, but I can't get my head round it. The demos are unclear  :(

How to create a memory DB, and perform simple SQL operations .....
« Last Edit: June 03, 2020, 01:59:37 pm by P.curtis »

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Dataset SQL
« Reply #3 on: June 03, 2020, 01:59:56 pm »
I've never used ZMSQL, so I cannot help specifically. Did you see the wiki https://wiki.lazarus.freepascal.org/ZMSQL?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Dataset SQL
« Reply #4 on: June 03, 2020, 04:12:01 pm »
How to create a memory DB, and perform simple SQL operations .....
Maybe you can explain WHY you want this.
With that information maybe some more useful suggestions can be given.

For example, SQLite can have a database in memory. And there are others.


P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Dataset SQL
« Reply #5 on: June 03, 2020, 05:42:44 pm »
I want it for speed, I just tried SQLite and it didn't suit me. A full blown server. MARIADB ..., is overkill.

A memory based DB is ideal for this applications requirements.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Dataset SQL
« Reply #6 on: June 03, 2020, 05:45:39 pm »
I want it for speed, I just tried SQLite and it didn't suit me. A full blown server. MARIADB ..., is overkill.

A memory based DB is ideal for this applications requirements.
SQLite isn't a full blown server. It's just a small dll. And with :memory: as connectionstring you can make a memory-database. What didn't suit you?

But ok... There are others.
https://en.m.wikipedia.org/wiki/List_of_in-memory_databases

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: Dataset SQL
« Reply #7 on: June 03, 2020, 06:16:49 pm »
A memory based DB is ideal for this applications requirements.
And SQL is overkill for a memory based DB. And if you want to change data like a update, iterate throug the DB. BTW: It is often better to use collections or specialiesd lists to get speed. 
regards
Andreas

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Dataset SQL
« Reply #8 on: June 03, 2020, 07:00:35 pm »
Thats why the second part of my question was how to handle something like an UPATE in this type of dataset.
« Last Edit: June 03, 2020, 07:18:51 pm by P.curtis »

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Dataset SQL
« Reply #9 on: June 03, 2020, 07:58:30 pm »
Why don't you use the TDataset methods Locate, Edit, Append, Post?

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Dataset SQL
« Reply #10 on: June 03, 2020, 10:12:48 pm »
Thats my point. If I have a DB of say 1000 records and I want to do an UPDATE that will affect a lot of the the records, do I have to LOCATE POST CHANGE DATA POST all the records or am I missing something?

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: Dataset SQL
« Reply #11 on: June 03, 2020, 10:17:18 pm »
I think you have do it in this way, if you use this db. No way out.

Is there a special indication for using THIS kind of db.
« Last Edit: June 03, 2020, 10:21:22 pm by af0815 »
regards
Andreas

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Dataset SQL
« Reply #12 on: June 03, 2020, 10:29:29 pm »
My first impression is: you have a memory dataset, and 1000 records is not much for an in-memory operation. Did you try? If you did: did you call Disable/EnableControls, or disconnect the visual controls from the datasource?

Try the attached demo. It uses a TBufDataset which comes with the default installation of Lazarus and is a memory dataset (similar to Delphi's ClientDataset). A click on the left button fills the dataset with 10,000 records (integer ID field, float X and Y fields) where the X field contains random integers from 0 to 9. A click on the right button iterates through all the records and replaces the Y value by Y*1000 when X=5. With about 1000 records affected this is completed in some tens of milliseconds.
« Last Edit: June 03, 2020, 11:03:22 pm by wp »

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Dataset SQL
« Reply #13 on: June 04, 2020, 09:39:13 am »
@WP Thanks for your input. I have decided to go the SQLite way. Which has produced more headaches >:(

I'll post another question.

Thanks.

 

TinyPortal © 2005-2018