Readonly dataset. lazarus / 16-Databases ---------------------------------------------------------------------- P.curtis · 2020-06-04 07:49 I execute Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   SQLQuery1.LoadFromFile('playlist');  SQLQuery1.Append;  ....  SQLQuery1.Post;  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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   SQLQuery1.SaveToFile('playlist');  This works without problem. The file is created and contains data, but when I try to load it back Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   SQLQuery1.LoadFromFile('playlist');  and edit it I get the error that the dataset is readonly. ---------------------------------------------------------------------- zoltanleo · 2020-06-04 10:13 TSQLQuery component has the properties of InsertSQL, UpdateSQL etc. Perhaps you have left them empty. ---------------------------------------------------------------------- P.curtis · 2020-06-04 10:23 What do you mean? What should I put there? ---------------------------------------------------------------------- mangakissa · 2020-06-04 10:49 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. ---------------------------------------------------------------------- P.curtis · 2020-06-04 11:46 I need SQL capability ---------------------------------------------------------------------- rvk · 2020-06-04 12:17 Quote from: P.curtis on June 04, 2020, 09:49:06 amI execute Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   SQLQuery1.LoadFromFile('playlist');  SQLQuery1.Append;  ....  SQLQuery1.Post; 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 · 2020-06-04 12:22 The error comes from the append line. ---------------------------------------------------------------------- rvk · 2020-06-04 12:36 Quote from: P.curtis on June 04, 2020, 02:22:59 pmThe 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 · 2020-06-04 12:42 I made a small prog. to show my problem. ---------------------------------------------------------------------- rvk · 2020-06-04 12:57 Quote from: P.curtis on June 04, 2020, 02:42:52 pmI 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/top ic,17479.msg96592.html#msg96592 (i.e. TSQLite3Backup) TSQLQuery.SaveToFile and TSQLQuery.LoadFromFile are not for this purpose. ---------------------------------------------------------------------- mangakissa · 2020-06-04 13:13 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. ---------------------------------------------------------------------- rvk · 2020-06-04 13:20 Quote from: mangakissa on June 04, 2020, 03:13:03 pmWhat 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 · 2020-06-04 13:38 @rvk Thanks for making it clear. I? will write my own import / export db functions. ---------------------------------------------------------------------- beerman · 2025-04-03 20:46 Today I had the same issue, 'Dataset is read-only'. Took a little while. On the TSQLQuery in use, property SQL, (TStringList), I had a SELECT * statement for MYSQL and just above it had a short comment: '#Comment'. Turns out, when I substituted /*Comment*/ and dropped use of the '#', the issue of 'Dataset is read-only' disappeared. Cheers!