Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stored Procedure

Posted on 2004-04-15
9
Medium Priority
?
234 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

730 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