• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

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

0
rarigo
Asked:
rarigo
  • 6
  • 2
  • 2
  • +2
1 Solution
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
 
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

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 6
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now