【问题标题】:Return code of doing an update query with ADOquery in Delphi to PostgreSQL在 Delphi 中使用 ADOquery 向 PostgreSQL 执行更新查询的返回代码
【发布时间】:2013-04-17 12:32:19
【问题描述】:

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

代码:

Adoquery1.close;
Adoquery1.SQL.Clear;
query := 'insert into  testtabel (nummer, naam) values (3,''Barnsten'') ';
Adoquery1.SQL.Add(query ) ;
result := Adoquery1.ExecSql;

结果是-1

【问题讨论】:

  • 为什么不使用通常的InsertPost 机制?
  • 可能后面没有DBAware控件?
  • 如果在调用 Adoquery1.ExecSQL; 之后添加 AdoQuery1.Close; AdoQuery1.SQL.Text := SELECT nummer, naam FROM testtabel where nummer = 3 and naam = ''Barnsten'' 会发生什么); AdoQuery1.打开; ShowMessage('Result: ' + IntToStr(ADOQuery1.RowCount));? Do you get 1? If not, the INSERT` 失败,你从RowsAffected 得到的值是正确的。 Open 不使用RowsAffected;它使用 RowCount 代替 IIRC。
  • testtabel 有没有被分区?

标签: delphi tadoquery


【解决方案1】:
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)')
    ));

返回我 3。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-13
    • 2019-02-20
    • 1970-01-01
    • 2018-06-07
    • 2021-11-12
    • 2016-01-29
    • 2014-05-23
    • 1970-01-01
    相关资源
    最近更新 更多