Board index » delphi » "Prepare" cause error

"Prepare" cause error

Using DB2 UDB 6.1 on NT; Delphi 4 & BDE 5.1 on Window95

Referring to the following source, after I "prepare" the TQuery, pass the
parameters and ExecSQL, it preforms correctly.
However, after the second set of parameters and call ExecSQL, it fail and
give General SQL error.
If I remove the "prepare" statement, then it works fine!

The program source:

  with query1 do
  begin
    Sql.Add(' INSERT INTO URRHT2 (URGRP_ID, FNC_ID, ISGROUP)');
    Sql.Add('VALUES ( :P1, :P2, ''F'')');
    Prepare;
    ParamByName('P1').AsString := '11';
    ParamByName('P2').AsString := '22';
    ExecSQL;        // That line work normal
    ParamByName('P1').AsString := '23';
    ParamByName('P2').AsString := '34';
    ExecSQL;      // That line give "General SQL error"
  end;

 

Re:"Prepare" cause error


I think you need to call Query1.Close after the first ExecSQL.

Re:"Prepare" cause error


Thank your suggestion, but it did not help. It become normal if I remove the
"prepare" statement!

Unfortunately, my suitation is porting a MS SQL application to DB2.
It is ideal if a "system" solution can solve this problem.

I don't kown it is a fault/nature of BDE or DB2. It is better to have an
option setting to solve this problem?

Quote
"Richard Simpson" <Richard.Simp...@mail.house.gov> wrote in message

news:864gav$frd26@bornews.borland.com...
Quote
> I think you need to call Query1.Close after the first ExecSQL.

Re:"Prepare" cause error


Quote
In article <8634g5$f7...@bornews.borland.com>, "dickson Wong" <dick...@cac.com.hk> wrote:
>Using DB2 UDB 6.1 on NT; Delphi 4 & BDE 5.1 on Window95

>Referring to the following source, after I "prepare" the TQuery, pass the
>parameters and ExecSQL, it preforms correctly.
>However, after the second set of parameters and call ExecSQL, it fail and
>give General SQL error.
>If I remove the "prepare" statement, then it works fine!

>The program source:

>  with query1 do
>  begin
>    Sql.Add(' INSERT INTO URRHT2 (URGRP_ID, FNC_ID, ISGROUP)');
>    Sql.Add('VALUES ( :P1, :P2, ''F'')');
>    Prepare;
>    ParamByName('P1').AsString := '11';
>    ParamByName('P2').AsString := '22';
>    ExecSQL;        // That line work normal
>    ParamByName('P1').AsString := '23';
>    ParamByName('P2').AsString := '34';
>    ExecSQL;      // That line give "General SQL error"
>  end;

Try This:
Its a bit of long way, but I should work

Quote
>  with query1 do
>  begin
SQL.CLEAR;
>    Sql.Add(' INSERT INTO URRHT2 (URGRP_ID, FNC_ID, ISGROUP)');
>    Sql.Add('VALUES ( :P1, :P2, ''F'')');
>    Prepare;
>    ParamByName('P1').AsString := '11';
>    ParamByName('P2').AsString := '22';
>    ExecSQL;        // That line work normal

QUERY.CLOSE
QUERY.UNPREPARE;
SQL.CLEAR:
Quote
>    Sql.Add(' INSERT INTO URRHT2 (URGRP_ID, FNC_ID, ISGROUP)');
>    Sql.Add('VALUES ( :P1, :P2, ''F'')');
>    ParamByName('P1').AsString := '23';
>    ParamByName('P2').AsString := '34';
>    ExecSQL;      // That line give "General SQL error"

QUERY.CLOSE
QUERY.UNPREPARE;

Quote
>  end;

Marcel Schoch
Web Site : http://webhome.idirect.com/~redblack/

Other Threads