Recent

Author Topic: Readonly dataset.  (Read 1921 times)

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Readonly dataset.
« on: June 04, 2020, 09:49:06 am »
I execute

Code: Pascal  [Select][+][-]
  1.   SQLQuery1.LoadFromFile('playlist');
  2.   SQLQuery1.Append;
  3.   ....
  4.   SQLQuery1.Post;
  5.  

and I get an error that the dataset is read only.

What gives? How can I fix this?

Basically I have a program that creates a DB.
This I can save with

Code: Pascal  [Select][+][-]
  1.   SQLQuery1.SaveToFile('playlist');
  2.  

This works without problem. The file is created and contains data, but when I try to load it back

Code: Pascal  [Select][+][-]
  1.   SQLQuery1.LoadFromFile('playlist');
  2.  

and edit it I get the error that the dataset is readonly.

zoltanleo

  • Sr. Member
  • ****
  • Posts: 488
Re: Readonly dataset.
« Reply #1 on: June 04, 2020, 12:13:54 pm »
TSQLQuery component has the properties of InsertSQL, UpdateSQL etc. Perhaps you have left them empty.
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Readonly dataset.
« Reply #2 on: June 04, 2020, 12:23:32 pm »
What do you mean?

What should I put there?

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Readonly dataset.
« Reply #3 on: June 04, 2020, 12:49:39 pm »
I never used TSQLquery to load data from file. I know TSQLQuery derived from TBufdataset and I find it strange get have the procedure loadfromfile.

I shall choose TBufdataset directly. It wil read xml at once and procedures append / edit and post should work.

It still better to use objects if you want to work with memory.
« Last Edit: June 04, 2020, 01:08:10 pm by mangakissa »
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Readonly dataset.
« Reply #4 on: June 04, 2020, 01:46:40 pm »
I need SQL capability

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Readonly dataset.
« Reply #5 on: June 04, 2020, 02:17:53 pm »
I execute
Code: Pascal  [Select][+][-]
  1.   SQLQuery1.LoadFromFile('playlist');
  2.   SQLQuery1.Append;
  3.   ....
  4.   SQLQuery1.Post;
  5.  
and I get an error that the dataset is read only.
Do you get the error on the LoadFromFile() line, or on the SQLQuery1.Append line ???

Did you fill the SQLQuery1.SQL.Text? If not... how would SQLQuery1 know how to handle the dataset?

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Readonly dataset.
« Reply #6 on: June 04, 2020, 02:22:59 pm »
The error comes from the append line.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Readonly dataset.
« Reply #7 on: June 04, 2020, 02:36:51 pm »
The error comes from the append line.
I think you can't edit a dataset which is loaded with LoadFromFile.

Where would that data be stored?
It's only active in memory, but the TSQLQuery is designed to receive it from a database-engine.
And TSQLQuery.LoadFromFile doesn't add records magically to a database.

For example... if you use SQLite, you can use :memory: to use a in-memory file you can backup and restore that memory to and from a file.
See https://www.sqlite.org/backup.html

I'm not sure how this is implemented in FPC.

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Readonly dataset.
« Reply #8 on: June 04, 2020, 02:42:52 pm »
I made a small prog. to show my problem.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Readonly dataset.
« Reply #9 on: June 04, 2020, 02:57:14 pm »
I made a small prog. to show my problem.
You haven't done anything with :memory: yet.

But as you can see... after SQLQuery1.LoadFromFile('playlist') if you look into the queue.db file, you don't see any data.
So TSQLQuery.LoadFromFile doesn't really add the data from playlist to the actual database. So anything you do isn't interacting with SQLite. I think that the dataset is read into the file as sort of a MemoryDataSet, which doesn't have editing capability. (But maybe someone can correct me if I'm wrong)

Anyway... like I said... if you have a :memory: SQLite database, you can backup and restore it.
Look at this thread https://forum.lazarus.freepascal.org/index.php/topic,17479.msg96592.html#msg96592
(i.e. TSQLite3Backup)

TSQLQuery.SaveToFile and TSQLQuery.LoadFromFile are not for this purpose.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Readonly dataset.
« Reply #10 on: June 04, 2020, 03:13:03 pm »
Offcourse it's readonly. Your'e using SQLQuery1.LoadFromFile('playlist') which has no connection to the database. When using a query from the database a internal provider is handling your data from and to the database. Now there's only a dataset to view. Nothing more.

What's your problem for not using SQL?

What you want is really a app with an (generic) objectlist and a json file. Nothing more. Than you are capable to use only memory.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Readonly dataset.
« Reply #11 on: June 04, 2020, 03:20:45 pm »
What you want is really a app with an (generic) objectlist and a json file. Nothing more. Than you are capable to use only memory.
P. wanted a SQL solution (to be able to effect multiple records with one command). It should be SQL capable and in-memory.

SQLite is perfect for that.
But you can't use LoadFromFile and SaveToFile for backup up that memory set.
You need to use TSQLite3Backup for that.

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: Readonly dataset.
« Reply #12 on: June 04, 2020, 03:38:37 pm »
@rvk Thanks for making it clear. I? will write my own import / export db functions.

 

TinyPortal © 2005-2018