[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Stored Procedure

Posted on 2004-04-15
9
Medium Priority
?
236 Views
Last Modified: 2010-04-05
I made a StoredProcedure to do an update on a table.:

ALTER PROCEDURE "CLIENTS"
(
  "CODE" INTEGER,
  "PURCHASE" DOUBLE PRECISION
)
AS
  BEGIN
    update CLIENTS
    set TOTAL = TOTAL + :PURCHASE
    where CLIENT_CODE = :CODE;
  END
 ^

Do I have to put a commit after the update or something ? Because when I execute the StoredProcedure from my application, then right after try to do an Edit on that table it gives me an Update Deadlock ! What´s wrong ??
0
Comment
Question by:fabyola
9 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10832298

   commit the transaction before execute the stored procedure ...
0
 
LVL 1

Expert Comment

by:psycho_cat_69
ID: 10832780
Try this

ALTER PROCEDURE "CLIENTS"
(
  "CODE" INTEGER,
  "PURCHASE" DOUBLE PRECISION
)
AS
    update CLIENTS
    set TOTAL = TOTAL + :PURCHASE
    where CLIENT_CODE = :CODE;
GO
0
 

Author Comment

by:fabyola
ID: 10833454
But do I have to do a commit after or does it do it for me automaticlly ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Accepted Solution

by:
esoftbg earned 200 total points
ID: 10837844
InterBase syntax:

ALTER PROCEDURE CLIENT_UPDATE
(
  CODE INTEGER,
  PURCHASE DOUBLE PRECISION
)
AS
  DECLARE VARIABLE DTOTAL DOUBLE PRECISION;
BEGIN
  select TOTAL from CLIENTS where CLIENT_CODE = :CODE into :DTOTAL;
  update CLIENTS set TOTAL = :DTOTAL + :PURCHASE where CLIENT_CODE = :CODE;
  SUSPEND;
END

//................

Delphi syntax:  IBQ: TIBQuery; IBTR: IBTransaction; CLIENT_UPDATE_: TIBStoredProc;

procedure TFormCLIENTS.Client_Update(Code: Integer; Purchase: Double);
var
  B:      Boolean;
  S:      string;
begin
  B := False;
  S := IBQ.FieldByName('CLIENT_CODE').AsString;
  if not IBTR.Active then
    IBTR.StartTransaction;
  try
    try
      CLIENT_UPDATE_.ParamByName('CODE').AsInteger := Code;
      CLIENT_UPDATE_.ParamByName('PURCHASE').AsFloat := Purchase;
      CLIENT_UPDATE_.ExecProc;
      B := True;
    except
      B := False;
    end;
  finally
    if IBTR.Active then
    begin
      if B then
      begin
        IBTR.Commit;
        IBQ.Active := True;
        IBQ.Locate('CLIENT_CODE', S, []);
      end
      else
        IBTR.Rollback;
    end;
  end;
end;
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10837863
>But do I have to do a commit after or does it do it for me automaticlly ?
TIBTransaction must be Activated before execution of a TIBStoredProc, and must be Commited after its execution.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10839869
A little bit improvement of above code:
      if B then
      begin
        IBTR.Commit;
        IBQ.Active := False; // It is better to be here in case IBQ and CLIENT_UPDATE_ use different TIBTransaction components
        IBQ.Active := True;
        IBQ.Locate('CLIENT_CODE', S, []);
      end
      else
        IBTR.Rollback;
0
 

Author Comment

by:fabyola
ID: 10858401
Ok but I do a Commit right after I execute the StoredProcedure
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10859821
right-click mouse button over the transaction componens and open the Transaction Editor (or double click). Select Read Commited. This will solve your problem.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10863353
if IBQ is a TIBTable and IBTQ is it's TIBTransaction, you must use the events:

procedure TFormCLIENTS.IBQBeforePost(DataSet: TDataSet);
begin
  if not IBTQ.Active then
    IBTQ.StartTransaction;
end;

procedure TFormCLIENTS.IBQAfterPost(DataSet: TDataSet);
begin
  if IBTQ.Active then
    IBTQ.CommitRetaining;
end;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question