Subject | SP runs 2 times ? Is this a bug in IBOBjects ? |
---|---|
Author | canadienii2000 |
Post date | 2003-09-24T13:24:06Z |
Dear friends,
I found something interesting:
I have a stored procedure in Interbase and I called this one in
Delphi, using IB_Query.
I realized that the stored procedure is running two times !!!
Here are the codes:
INTERBASE:
CREATE TABLE ATEST (
F1 INTEGER,
F2 SMALLINT);
INSERT INTO ATEST (F1,F2) VALUES (1,1);
INSERT INTO ATEST (F1,F2) VALUES (1,2);
INSERT INTO ATEST (F1,F2) VALUES (1,3);
INSERT INTO ATEST (F1,F2) VALUES (1,4);
INSERT INTO ATEST (F1,F2) VALUES (1,5);
INSERT INTO ATEST (F1,F2) VALUES (1,6);
CREATE TABLE AATEST (
T1 INTEGER,
T2 INTEGER,
T3 INTEGER);
CREATE PROCEDURE AATEST1
RETURNS (
PF1 INTEGER,
PF2 SMALLINT)
AS
DECLARE VARIABLE V1 SMALLINT;
begin
v1=0;
insert into aatest (t1,t2,t3) values (-1,-1,-1);
for
select f1, f2 from atest into :pf1,:pf2
do
begin
v1=v1+1;
update atest set f1=:pf1+1 where f2=:pf2;
insert into aatest (t1,t2,t3) values (:pf1,:pf2,:v1);
suspend;
end
end
DELPHI:
{********** begin Unit 1.pas************************}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, Grids, IB_Grid, IB_Components, IB_StoredProc;
type
TForm1 = class(TForm)
IB_DataSource1: TIB_DataSource;
IB_Query1: TIB_Query;
IB_Transaction1: TIB_Transaction;
IB_Connection1: TIB_Connection;
IB_Grid1: TIB_Grid;
Button1: TButton;
Memo1: TMemo;
IB_StoredProc1: TIB_StoredProc;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure IB_Query1PrepareSQL(Sender: TIB_Statement);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
IB_Transaction1.StartTransaction;
IB_Query1.Close;
IB_Query1.SQL.Clear;
IB_Query1.SQL.Add('select * from AATEST1');
IB_Query1.Open;
IB_Transaction1.Commit;
{
IB_StoredProc1.Prepare;
IB_StoredProc1.Open;
}
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IB_Query1.Close;
// IB_StoredProc1.Close;
end;
procedure TForm1.IB_Query1PrepareSQL(Sender: TIB_Statement);
begin
ShowMessage('onpreparesql');
end;
end.
{********** END Unit 1.pas************************}
{********** begin Unit 1.dfm************************}
object Form1: TForm1
Left = 306
Top = 109
Width = 294
Height = 262
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object IB_Grid1: TIB_Grid
Left = 0
Top = 48
Width = 281
Height = 153
CustomGlyphsSupplied = []
DataSource = IB_DataSource1
TabOrder = 0
end
object Button1: TButton
Left = 0
Top = 208
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object Memo1: TMemo
Left = 0
Top = 0
Width = 281
Height = 41
Lines.Strings = (
'This program is trying to show if a Stored Procedure called '
'in Delphi is running 1 or 2 times.')
TabOrder = 2
end
object IB_DataSource1: TIB_DataSource
Dataset = IB_Query1
Left = 96
Top = 8
end
object IB_Query1: TIB_Query
DatabaseName = 'dagobah:var/interbase/test/moving2.gdb'
IB_Connection = IB_Connection1
SQL.Strings = (
'')
OnPrepareSQL = IB_Query1PrepareSQL
ColorScheme = False
MasterSearchFlags = [msfOpenMasterOnOpen,
msfSearchAppliesToMasterOnly]
BufferSynchroFlags = []
CommitAction = caRefresh
FetchWholeRows = True
Left = 128
Top = 8
end
object IB_Transaction1: TIB_Transaction
IB_Connection = IB_Connection1
Isolation = tiConcurrency
Left = 224
Top = 8
end
object IB_Connection1: TIB_Connection
DefaultTransaction = IB_Transaction1
Params.Strings = (
'SERVER=dagobah'
'PROTOCOL=TCP/IP'
'PATH=var/interbase/test/moving2.gdb'
'USER NAME=sysdba'
'PASSWORD=masterkey')
Left = 192
Top = 8
end
object IB_StoredProc1: TIB_StoredProc
DatabaseName = 'dagobah:var/interbase/test/moving2.gdb'
IB_Connection = IB_Connection1
SQL.Strings = (
'EXECUTE PROCEDURE AATEST1')
AutoDefineParams = False
StoredProcName = 'AATEST1'
Left = 160
Top = 24
end
end
{********************************************}
If you will run this example, the result will be written in AATEST
table. Here you will see each time when you press "Button1", the first
line in SP:
insert into aatest (t1,t2,t3) values (-1,-1,-1);
will apear two times.
I'm looking for your comments.
Jean
I found something interesting:
I have a stored procedure in Interbase and I called this one in
Delphi, using IB_Query.
I realized that the stored procedure is running two times !!!
Here are the codes:
INTERBASE:
CREATE TABLE ATEST (
F1 INTEGER,
F2 SMALLINT);
INSERT INTO ATEST (F1,F2) VALUES (1,1);
INSERT INTO ATEST (F1,F2) VALUES (1,2);
INSERT INTO ATEST (F1,F2) VALUES (1,3);
INSERT INTO ATEST (F1,F2) VALUES (1,4);
INSERT INTO ATEST (F1,F2) VALUES (1,5);
INSERT INTO ATEST (F1,F2) VALUES (1,6);
CREATE TABLE AATEST (
T1 INTEGER,
T2 INTEGER,
T3 INTEGER);
CREATE PROCEDURE AATEST1
RETURNS (
PF1 INTEGER,
PF2 SMALLINT)
AS
DECLARE VARIABLE V1 SMALLINT;
begin
v1=0;
insert into aatest (t1,t2,t3) values (-1,-1,-1);
for
select f1, f2 from atest into :pf1,:pf2
do
begin
v1=v1+1;
update atest set f1=:pf1+1 where f2=:pf2;
insert into aatest (t1,t2,t3) values (:pf1,:pf2,:v1);
suspend;
end
end
DELPHI:
{********** begin Unit 1.pas************************}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, Grids, IB_Grid, IB_Components, IB_StoredProc;
type
TForm1 = class(TForm)
IB_DataSource1: TIB_DataSource;
IB_Query1: TIB_Query;
IB_Transaction1: TIB_Transaction;
IB_Connection1: TIB_Connection;
IB_Grid1: TIB_Grid;
Button1: TButton;
Memo1: TMemo;
IB_StoredProc1: TIB_StoredProc;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure IB_Query1PrepareSQL(Sender: TIB_Statement);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
IB_Transaction1.StartTransaction;
IB_Query1.Close;
IB_Query1.SQL.Clear;
IB_Query1.SQL.Add('select * from AATEST1');
IB_Query1.Open;
IB_Transaction1.Commit;
{
IB_StoredProc1.Prepare;
IB_StoredProc1.Open;
}
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IB_Query1.Close;
// IB_StoredProc1.Close;
end;
procedure TForm1.IB_Query1PrepareSQL(Sender: TIB_Statement);
begin
ShowMessage('onpreparesql');
end;
end.
{********** END Unit 1.pas************************}
{********** begin Unit 1.dfm************************}
object Form1: TForm1
Left = 306
Top = 109
Width = 294
Height = 262
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object IB_Grid1: TIB_Grid
Left = 0
Top = 48
Width = 281
Height = 153
CustomGlyphsSupplied = []
DataSource = IB_DataSource1
TabOrder = 0
end
object Button1: TButton
Left = 0
Top = 208
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object Memo1: TMemo
Left = 0
Top = 0
Width = 281
Height = 41
Lines.Strings = (
'This program is trying to show if a Stored Procedure called '
'in Delphi is running 1 or 2 times.')
TabOrder = 2
end
object IB_DataSource1: TIB_DataSource
Dataset = IB_Query1
Left = 96
Top = 8
end
object IB_Query1: TIB_Query
DatabaseName = 'dagobah:var/interbase/test/moving2.gdb'
IB_Connection = IB_Connection1
SQL.Strings = (
'')
OnPrepareSQL = IB_Query1PrepareSQL
ColorScheme = False
MasterSearchFlags = [msfOpenMasterOnOpen,
msfSearchAppliesToMasterOnly]
BufferSynchroFlags = []
CommitAction = caRefresh
FetchWholeRows = True
Left = 128
Top = 8
end
object IB_Transaction1: TIB_Transaction
IB_Connection = IB_Connection1
Isolation = tiConcurrency
Left = 224
Top = 8
end
object IB_Connection1: TIB_Connection
DefaultTransaction = IB_Transaction1
Params.Strings = (
'SERVER=dagobah'
'PROTOCOL=TCP/IP'
'PATH=var/interbase/test/moving2.gdb'
'USER NAME=sysdba'
'PASSWORD=masterkey')
Left = 192
Top = 8
end
object IB_StoredProc1: TIB_StoredProc
DatabaseName = 'dagobah:var/interbase/test/moving2.gdb'
IB_Connection = IB_Connection1
SQL.Strings = (
'EXECUTE PROCEDURE AATEST1')
AutoDefineParams = False
StoredProcName = 'AATEST1'
Left = 160
Top = 24
end
end
{********************************************}
If you will run this example, the result will be written in AATEST
table. Here you will see each time when you press "Button1", the first
line in SP:
insert into aatest (t1,t2,t3) values (-1,-1,-1);
will apear two times.
I'm looking for your comments.
Jean