3

I'm using Adoquery with a Postgres database. When I do an UPDATE or INSERT query the ExecSql nor the OPEN returns the number of affected records as it should , but always -1. I use the newest version of psqlODBC : 09.01.0200.

Code:

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

Result is -1

S-Man
  • 22,521
  • 7
  • 40
  • 63
  • Why don't you just use the usual `Insert` and `Post` mechanism? – Jens Mühlenhoff Apr 17 '13 at 12:56
  • Maybe there is no DBAware control behind? – pf1957 Apr 17 '13 at 13:15
  • What happens if right after the call to `Adoquery1.ExecSQL;`, you add `AdoQuery1.Close; AdoQuery1.SQL.Text := `SELECT nummer, naam FROM testtabel where nummer = 3 and naam = ''Barnsten''); AdoQuery1.Open; ShowMessage('Result: ' + IntToStr(ADOQuery1.RowCount));`? Do you get `1`? If not, the `INSERT` failed, and the value you got from `RowsAffected` was correct. `Open` doesn't use `RowsAffected`; it uses `RowCount` instead, IIRC. – Ken White Apr 17 '13 at 23:03
  • 1
    Is `testtabel` partitioned by any chance? – Craig Ringer Apr 18 '13 at 00:53

1 Answers1

0
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)')
    ));

Returns me 3.

Edijs Kolesnikovičs
  • 1,627
  • 3
  • 18
  • 34