Solved

Stored Procedure

Posted on 2004-04-15
9
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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!

 
LVL 12

Accepted Solution

by:
esoftbg earned 50 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

624 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