CALL BACK IN STORED PROCEDURE

Hi Experts Guys,
     
When I call a stored procedure the control doesn't return to program until the procedure is not finished but I would like to implement a gauge for instance. How could I implement this?

Thanks,

Sinceramente,
Reginaldo

rarigoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
Listening
0
snoop_doggy_doggCommented:
I'm not sure if it would be worth the effort, but if your database supports "extended stored-procedures" then you could make a call to one created with Delphi while your other stored procedure is iterating through a cursor (for example) which sends a message to your client which called the original procedure inside a thread...

Just a thought.

Woof!
http://www.woofwoofwoof.com
0
kubeerjaCommented:
you can simply do the following:
-inside your stored proc update a table in your database each time you finish one process in your stored proc.
-in delphi keep reading that table and check the processing of your proc, may be you have to use a different thread.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

XANCommented:
you should call stored procedure from the single thread and then you can implement any "callback functionality" by self
0
snoop_doggy_doggCommented:
Huh?
0
rarigoAuthor Commented:
would you mind providing me some code implementing your idea so i could just test it?
Because i've tried some ideas with new threads and it just didn't work either.
0
rarigoAuthor Commented:
kubberja: the real problem is that i don't have time to read that updated table even in another thread. Because if i had that time i wouldn't be asking this question. :-(


0
XANCommented:
If I understand you, it should work right.

type
  TSPThread = class(TThread)
  private
    FSPName: string;
  protected
    procedure Execute; override;
  public
    property StoredProcedure: string read FSPName write FSPName;
  end;

{ TSPThread }

procedure TSPThread.Execute;
var
  Con: Connection;
  Cmd: Command;
  Affected: OleVariant;
  Params: OleVariant;
begin
  { should be   FreeOnTerminate = True   }
  Con := CoConnection.Create;
  Con.ConnectionString := strConnectionString;
  Cmd := CoCommand.Create;
  Cmd.Set_ActiveConnection(Con);
  Cmd.CommandText := FSPName;
  Cmd.CommandType := adCmdStoredProc;
  { ...
    any parameters and other prepare
    ... }
  Cmd.Execute(Affected, Params, adCmdStoredProc);
  { After stored procedure are completed thread terminates and free itself }
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TSPThread.Create(True) do
  begin
    StoredProcedure := 'StoredProcedureName';
    FreeOnTerminate := True; { it is default value }
    Resume;
  end;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rarigoAuthor Commented:
Hi XAN,
 
    Looks like a good piece of code i'll test it on Monday at work. Talk to you later. Thanks.

Sinceramente,
Reginaldo
0
rarigoAuthor Commented:
Hi XAN,
 
    Looks like a good piece of code i'll test it on Monday at work. Talk to you later. Thanks.

Sinceramente,
Reginaldo
0
rarigoAuthor Commented:
Hi Xan,

    As I said before I can only test this code at work but I tried to compile it here at home then came to know that it is not for Delphi 3.0 which is the version we use at work.

    And now what?


Sinceramente,
Reginaldo





0
kubeerjaCommented:
Xan is using ADO to run the procedure , you have to import ADO type library in order to compile this code.
0
rarigoAuthor Commented:
Hi Xan,

    My code turned out to be this way:


type
  TSPThread   = class( TThread )
  protected
     procedure Execute; override;
  end;


procedure TSPThread.Execute;
begin
   FrmUpt79900.stp_ExpDados.ExecProc;
end;


Procedure TFrmUpt79900.BtnGravarClick(Sender: TObject);
begin
   Screen.Cursor   := crHourglass;
   try
    with stp_ExpDados do
     begin
       if (Cod_Sistema = 'MS') or (Cod_Sistema = 'S7') or (Cod_Sistema = 'SY') then
       begin
         ParamByName ('@EMP').AsInteger := Empresa;
         ParamByName ('@DTBASE').AsDate := StrToDate (cbxDtBase.Text);
       end;
       SPExecuting := true;
       Animate.Active := true;
       with TSPThread.Create(True) do
       begin
         FreeOnTerminate := True;
         Priority := tpNormal;
         OnTerminate := SPExecuted;
         Resume;
       end;
    end;
   except
       MessageDlg ('Erro Exportando Registros ', mterror, [mbOk],0);
       Exit;
   end;
end;

And I've created a timer to help me with the gauge, screen refreshs and so on. And it's working.
 

Thanks.


Sinceramente,
Reginaldo




0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.