使用Delphi中的ADOquery向PostgreSQL执行更新查询的返回代码

使用Delphi中的ADOquery向PostgreSQL执行更新查询的返回代码,delphi,tadoquery,Delphi,Tadoquery,我正在将Adoquery与Postgres数据库一起使用。 当我执行更新或插入查询时,ExecSql或OPEN会返回受影响记录的数量,但始终为-1。 我使用最新版本的PSQLDBC:09.01.0200 代码: 结果是-1函数PerformSQL(const ASQL:string):整数; function PerformSQL(const ASQL: string): integer; begin Result := -1; if ASQL <> '' then be

我正在将Adoquery与Postgres数据库一起使用。 当我执行更新或插入查询时,ExecSql或OPEN会返回受影响记录的数量,但始终为-1。 我使用最新版本的PSQLDBC:09.01.0200

代码:

结果是-1

函数PerformSQL(const ASQL:string):整数;
function PerformSQL(const ASQL: string): integer;
begin
  Result := -1;
  if ASQL <> '' then
  begin
    ZQuery1.SQL.Text := ASQL;
    ZQuery1.ExecSQL;
    Result := ZQuery1.RowsAffected;
  end;
end;



 ShowMessage
    (IntToStr(PerformSQL('insert into test(te_id, te_code, te_name, te_type)' +
    ' VALUES(DEFAULT, 15, ''tezty68'', 1), (DEFAULT, 16, ''teztx75'', 1), (DEFAULT, 18, ''teztx89'', 1)')
    ));
开始 结果:=-1; 如果ASQL为“”,则 开始 ZQuery1.SQL.Text:=ASQL; ZQuery1.ExecSQL; 结果:=ZQuery1.RowsAffected; 结束; 结束; 显示消息 (IntToStr(PerformSQL(‘插入测试(te_id、te_代码、te_名称、te_类型)’)+ '值(默认值,15,'tezty68',1),(默认值,16,'teztx75',1),(默认值,18,'teztx89',1)' ));

返回我3。

为什么不使用通常的
Insert
Post
机制?可能后面没有DBAware控件?如果在调用
Adoquery1.ExecSQL之后发生什么
,则添加
AdoQuery1.Close;AdoQuery1.SQL.Text:=
从测试表中选择nummer、naam,其中nummer=3,naam='Barnsten';AdoQuery1.打开;ShowMessage('Result:'+IntToStr(ADOQuery1.RowCount))<代码>?你得到了1
?如果没有,则
INSERT`失败,并且从
RowsAffected
获得的值是正确的<代码>打开不使用
行受影响
;它使用
RowCount
代替IIRC。是否有可能对
testtabel
进行分区?
function PerformSQL(const ASQL: string): integer;
begin
  Result := -1;
  if ASQL <> '' then
  begin
    ZQuery1.SQL.Text := ASQL;
    ZQuery1.ExecSQL;
    Result := ZQuery1.RowsAffected;
  end;
end;



 ShowMessage
    (IntToStr(PerformSQL('insert into test(te_id, te_code, te_name, te_type)' +
    ' VALUES(DEFAULT, 15, ''tezty68'', 1), (DEFAULT, 16, ''teztx75'', 1), (DEFAULT, 18, ''teztx89'', 1)')
    ));