Recent

Author Topic: Lazarus Access Database- Save Changes Procedure????  (Read 6215 times)

Synth

  • Newbie
  • Posts: 3
Lazarus Access Database- Save Changes Procedure????
« on: March 23, 2017, 10:30:37 am »
Hi Guys,
i am currently working on my A-Level project using Lazarus IDE and i am aiming to create a theoretical airline ticket booking system. So far i have managed to successfully create the database be able to link it to a DBGrid and have managed to add functions to add and delete from the database using Edit boxes, however i have been told that there is a way to directly edit the database via the DBGrid? Using a save changes procedure or something?? Would anyone be able to provide me with some sample code.

i am using SQLQuery and SQLTransactions aswell.

Feel free to email me at any time, i typically respond within minutes.

Much appreciated.

-Synth
« Last Edit: March 23, 2017, 10:34:20 am by Synth »

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #1 on: March 23, 2017, 12:57:09 pm »
You are looking for "commit"
Specialize a type, not a var.

Synth

  • Newbie
  • Posts: 3
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #2 on: March 23, 2017, 02:38:36 pm »
ive tried that

sky_khan

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #3 on: March 23, 2017, 04:01:12 pm »
fQ : TSQLQuery
fT : TSQLTransaction

Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnSaveClick(Sender: TObject);
  2. begin
  3.   fQ.ApplyUpdates;
  4.   fT.Commit;  
  5.   fQ.Open;  
  6. end;
  7.  

"Commit" closes datasets so you need to reopen it or you can use CommitRetaining but it is not advisable for long running processes because it may bloat the server/database

balazsszekely

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #4 on: March 23, 2017, 04:08:55 pm »
@SkyKhan

Instead of:
Code: Pascal  [Select][+][-]
  1. fT.Commit;  
  2. fQ.Open;
use:
Code: Pascal  [Select][+][-]
  1. fT.CommitRetaining;

sky_khan

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #5 on: March 23, 2017, 04:19:39 pm »
@Getmem

I guess you have not noticed my last sentence ?
I am not sure about others but I remember if you use CommitRetaining and never Commit it was choking Firebird for example when I was using it.

balazsszekely

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #6 on: March 23, 2017, 06:23:07 pm »
Quote
I guess you have not noticed my last sentence ?
Yes, apparently I missed your last sentence. Sorry!

Quote
I am not sure about others but I remember if you use CommitRetaining and never Commit it was choking Firebird for example when I was using it.
I'm using CommitRetaining for years, never had any issues with it. However if you can reproduce the bug, please report it, or attach a demo project so we can run a few test.

sky_khan

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #7 on: March 23, 2017, 06:57:30 pm »
It is not a bug and is not related to Lazarus. Its about database server. Long running transactions are heavy for servers. By using CommitRetaining you dont commit fully and keep server busy.
When you have dozens of clients connects server and keep your application open all day long you will start noticing how server getting slower and slower. I've witnessed this for Firebird at least.
Whatever, use CommitRetaining if you wish for not writing one more line but let me remind you this
http://stackoverflow.com/questions/37225122/does-using-commit-retaining-impair-firebird-performance

balazsszekely

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #8 on: March 23, 2017, 08:59:25 pm »
I don't mind writing a few more lines if I had to, but that's not the point. The point is I did not see any decrease in server speed, with multiple clients connected, although the program is in use for years. The stackoverflow link is not very convincing.     

sky_khan

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #9 on: March 23, 2017, 09:28:49 pm »
Yeah yeah, "it works here", right ?
Whatever. This is getting annoying. I said I personally witnessed this. What are you expecting me to say ? Sorry, I really dont care anymore if you are convinced or not and I have nothing to say more.

Excerpt from https://www.firebirdsql.org/file/documentation/papers_presentations/html/paper-fbent-impacting.html

Quote
Commit Retaining and “Autocommit”

Commit Retaining is a “feature” of Firebird that was inherited from the ancestor, InterBase. It was implemented as a means to retain server-side resources and keep them available for developers using Borland's rapid application development tools and the BDE, the generic data access layer that was used to connect Windows graphical applications to databases. Its purpose was to present a level playing field for RAD development, regardless of the database running at the back-end.

Autocommit—a client-side mechanism that rolls the statement-level Post and the transaction-level Commit phases into a single step—was provided to enable developers to avoid transactions altogether. In the RAD components, Commit Retaining and Autocommit were bound together. This fitted well with desktop databases like dBase and Paradox (whose engine is, in fact, the BDE!), which do not have transactions.

With Firebird (and InterBase), Commit Retaining causes transactions to remain interesting indefinitely. Garbage collection effectively ceases on the “standard” Borland RAD tools database application and any other applications that make use of Commit Retaining. Such systems are fraught with problems of progressively degrading performance that cannot be resolved except by shutting down the database and allowing these old transactions to die.

Autocommit and Commit Retaining are not restricted to the Borland tools, of course. They are supported by most data access interfaces and Commit Retaining is available in SQL, so it behoves the application developer to understand the effects and to use these features with extreme care and control.
Prev: Who Uses Firebird?

balazsszekely

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #10 on: March 23, 2017, 09:34:31 pm »
I agree! This is not constructive at all. I let the OP choose whatever method he/she prefers.

sky_khan

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #11 on: March 23, 2017, 10:10:20 pm »
You'll let the OP to choose ? How polite of you!

- I saw a wolf at backyard and got frightened last night
* I did not see anything. There is nothing to fear

Guess who is who above. Lol! This is ridiculous, you know?

You didnt see any ill-effect of CommitRetaining. Well, who cares ? I dont. I said I experienced it myself.
Firebird's own documents says " Garbage collection effectively ceases on the applications that make use of Commit Retaining."
I'm just stating that. I still dont get Why I had to argue with you ?

You know, I'm really getting to lose my wish to participate this forum day by day because of these kind of arguments. I believe this is nonsense.
Come on, argue with that, I say "I believe this argument in this thread was nonsense".

I bet You will argue again ? Because CommitRetaining does no harm because you didnt observe any,  and you had to say it ? Right ?

Well, Goodbye folks, I dont think I would open this forum for a while.

Synth

  • Newbie
  • Posts: 3
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #12 on: March 23, 2017, 11:39:59 pm »
Doesn't there need to be anything inside an SQLQuery statement?

As I've tried the ApplyUpdates(); and then committing the transaction and then reopening the query.

It still doesn't seem to work?


balazsszekely

  • Guest
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #13 on: March 24, 2017, 07:30:32 am »
@Synth

Sorry for the noise, I will make a test project as soon as possible.

PS: PM sent.
« Last Edit: March 24, 2017, 10:06:26 am by GetMem »

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Lazarus Access Database- Save Changes Procedure????
« Reply #14 on: March 24, 2017, 05:27:46 pm »
@SkyKhan

Instead of:
Code: Pascal  [Select][+][-]
  1. fT.Commit;  
  2. fQ.Open;
use:
Code: Pascal  [Select][+][-]
  1. fT.CommitRetaining;

Even though it works, CommitRetaining should be avoided or, at least, used with EXTREME CARE on transactional database servers, specially on all versions of Firebird SQL Server.
The reason is simple: transactions should be committed as soon as possible.
When transactions take too long to be committed, they tend to worse the performance of the database server.
Of course, this may not be noted by non-DBA on database servers with less than 20 simultaneous active connections, but everyone using your DB program when 100+ simultaneous active connections can easily realize that your DB program is too slow.

 

TinyPortal © 2005-2018