Recent

Author Topic: DBNavigator  (Read 421 times)

TonyR500

  • New Member
  • *
  • Posts: 11
DBNavigator
« on: July 09, 2020, 08:47:10 pm »
Hi
Could someone help with this one.
I have to rewrite a Delphi application which records customer contact information and is used in the Sales Office of my customer.

I have a main form with sqlquery, sqltransaction, sqlite3connection and datasource. There is also a DBGrid and a DBNavigator. The sqlite3connection is linked to a sqlite3 database.

Getting the DBNavigator to work is the problem.

I need to be able to edit and change records and to add and delete records. Whenever I try to do any of these including clicking the Post button nothing happens. The changes are not recorded in the datatable and they are not retained in the grid.

I recall that in Delphi you could drop a Navigator component onto a form, connect it to the datatable and it would work "straight out of the box". It seems more complex with Lazarus.
Perhaps some code is needed ? Perhaps the answer lies with sqlquery ?

Could someone tell me exactly what is required to get DBNavigator working properly.

Many Thanks

dsiders

  • Sr. Member
  • ****
  • Posts: 375
Re: DBNavigator
« Reply #1 on: July 09, 2020, 09:29:16 pm »
Hi
Could someone help with this one.
I have to rewrite a Delphi application which records customer contact information and is used in the Sales Office of my customer.

I have a main form with sqlquery, sqltransaction, sqlite3connection and datasource. There is also a DBGrid and a DBNavigator. The sqlite3connection is linked to a sqlite3 database.

Getting the DBNavigator to work is the problem.

I need to be able to edit and change records and to add and delete records. Whenever I try to do any of these including clicking the Post button nothing happens. The changes are not recorded in the datatable and they are not retained in the grid.

I recall that in Delphi you could drop a Navigator component onto a form, connect it to the datatable and it would work "straight out of the box". It seems more complex with Lazarus.
Perhaps some code is needed ? Perhaps the answer lies with sqlquery ?

Could someone tell me exactly what is required to get DBNavigator working properly.

Many Thanks

Sounds like you're not commiting changes to the database, IOW, explicitly calling the Commit method in SqlTransaction.

The examples/database/image_mushrooms program is a good starting point.
« Last Edit: July 09, 2020, 09:52:25 pm by dsiders »
Lazarus 2.1 (SVN) / FPC 3.0.4 / FPC 3.2.0 / x86-win64 / Windows 8.1

TonyR500

  • New Member
  • *
  • Posts: 11
Re: DBNavigator
« Reply #2 on: July 10, 2020, 11:18:37 am »
Hi
Thanks for help.
After some research on the web I have put the following code in an OnClose event in Unit1

begin
SQLQuery1.Edit;
SQLQuery1.UpDateMode :=UpWhereChanged;
SQLQuery1.ApplyUpdates;
SQLTransaction1.Commit:
SQLQuery1.Close;
SQLQuery1.Open;
end;

Now when I run this in the IDE I get a Hint:- Parameter "CloseAction" not used

When I ran the executable outside of Lazarus last night about 11 pm it ran successfully
and changes I made in the grid were retained in the grid and passed to the database and, no error messages.

What is frustrating is that when I run the same executable this morning I get an error message "database is locked". So last night OK. This morning database is locked.

Grateful for any ideas, suggestions

Thanks AJR

TonyR500

  • New Member
  • *
  • Posts: 11
Re: DBNavigator
« Reply #3 on: July 10, 2020, 12:05:20 pm »
Hi
OK since my last post (database is locked issue) I have done some more work and I think I know what's causing it. If I run the project executable from the project folder with Lazarus still open but reduced to the task bar I get the "database is locked" error. If I run the executable from its folder with Lazarus completely closed there is no such error message and everything works ok.
AJR

mig-31

  • Sr. Member
  • ****
  • Posts: 279
Re: DBNavigator
« Reply #4 on: July 10, 2020, 01:19:41 pm »
SQLite is a single user database. Database is locked, because is already opened in the Larazus - "first connection". When you run your project from Lazarus or by cliked on binary file, you try to establish the second connection, which not allowed.
« Last Edit: July 10, 2020, 01:21:31 pm by mig-31 »
Lazarus 2.0.6 - CentOS 7.x, Mageia 7.1

TonyR500

  • New Member
  • *
  • Posts: 11
Re: DBNavigator
« Reply #5 on: July 10, 2020, 05:14:51 pm »
OK Thanks, to mig-31, for your interest. I had more or less come to the same conclusion myself. Good to have it confirmed by an expert.

Thanks
AJR

 

TinyPortal © 2005-2018