Recent

Author Topic: problen updating lazarus / sqlite database using a dbgrid  (Read 824 times)

steveinalabama

  • New Member
  • *
  • Posts: 40
problen updating lazarus / sqlite database using a dbgrid
« on: September 23, 2024, 09:20:35 pm »
Using Lazarus with sqlite3 and a dbgrid

Originally I tried using the dbnavigator buttons to edit, then types in my values, then used the navigator post button
but the updates were not done.

I tried adding apply uodates beofre the close statement I have tied to a button used to exit the progra
but it gives error message along the lines are no row is in edit or insert status.

I then added a new button names updates and using post or appl updates did not compile.

Finally I created a limited work around ... I added a second sql quary and the edit button

procedure TForm1.Button3Click(Sender: TObject);  // updates button
begin
   showmessage('new logic');
  sqlquery2.close;
  sqlquery2.SQL.clear;
  sqlquery2.sql.add('update myreminders set reminder_seen = 99') ;
  //applyupdates; not works
  sqlquery2.execsql;
  sqltransaction1.commit;

  // previous attempts ... none compiled or ran
  //  sqlquery2.post;
//  sqlquery2.applyupdates;
//sqlite3connection1.applyupdates(9);
end;   

The obvious problem is that it is hard coded, does not get values from the dbgrid,
does not know the recod key so it updates all records.
All the internet help I've read have you us the query fieldbyname function or the query fields.
Totally unusable as the query has not been updated yet.

The simplest solution would be if someone could upload a simple lazarus program using sqlite database with a dbgrid
able to update any field in the dbgrid.

Does anybody have or know of such a program?
Thanks.

TRon

  • Hero Member
  • *****
  • Posts: 3776
Re: problen updating lazarus / sqlite database using a dbgrid
« Reply #1 on: September 23, 2024, 10:32:27 pm »
The simplest solution would be if someone could upload a simple lazarus program using sqlite database with a dbgrid
able to update any field in the dbgrid.
Instead of someone making an explicit example for you it could be more helpful having a look at one of the many examples accompanied with Lazarus or have look at the wiki. In particular this example
I do not have to remember anything anymore thanks to total-recall.

dseligo

  • Hero Member
  • *****
  • Posts: 1443
Re: problen updating lazarus / sqlite database using a dbgrid
« Reply #2 on: September 23, 2024, 11:28:17 pm »
The simplest solution would be if someone could upload a simple lazarus program using sqlite database with a dbgrid
able to update any field in the dbgrid.

Here you go.

steveinalabama

  • New Member
  • *
  • Posts: 40
Re: problen updating lazarus / sqlite database using a dbgrid
« Reply #3 on: September 24, 2024, 05:37:15 pm »
Thank you Deseligo, for creating the zip file for me, but sorry to say I cannot run it.
It ran initially, and I wanted to put some buttons on the form, and it went downhill from there.
I tried deleting my changes but no luck.

I got ouut of Lazarus, unzipped the zip file again into a new folder. If opened the pas file in Lazarus and
it worked, thank you. But I got out of Lazarus, dent into dbbrowser and saw the 4 records I just created from
the dbgrid. The dat was there but I made no table changes in DBBrowser. I exited, went back into Lazarus
and compiled it but only an empty form appeared. I checked that the dbgrid was visible propery was set to visible, tried to
build, then compile and it fails with something like "cannot create the output EXE file. But no program was running, liust Lazarus itself.
I rebooted and started again, and still nothing appears on the form. Task manager shows nothing running except Lazarus.

I went into appdata to delete the project1.exe file but it will nt delete...says it is in use. After a reboot I was able to get into
appdata and delete project1.exe. I want into Lazarus, did a close all because it has an empty for1 and pass file.
After run without debugging, no form appears and no other programs are running... same result.

I saved the project as a different name to get around the cannot create output file, but still get a form1 with no grid on it.
I ulso changed the form name to form1b but running it still shows an empty form1.

Any suggestions on my next step?
Thank you for your help.






dseligo

  • Hero Member
  • *****
  • Posts: 1443
Re: problen updating lazarus / sqlite database using a dbgrid
« Reply #4 on: September 25, 2024, 10:42:35 am »
Any suggestions on my next step?
Thank you for your help.

I am not sure I'd understood your post completely, but I'm pretty sure that there is something else going on at your end.
You are describing many issues: loss of data after restarting program, can't delete .exe, corruption of form.

What OS and version of Lazarus do you have?

 

TinyPortal © 2005-2018