Solved

Stored Procedure

Posted on 2004-04-15
9
227 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process Javascript errors with Delphi TWebBrowser 1 129
Intraweb download file link ? 1 132
Dev Express grid collapse 2 44
Firemonkey webbrowser scrollbars ? 1 37
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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now