2013-04-17 75 views
3

我使用Adoquery和Postgres數據庫。 當我執行UPDATE或INSERT查詢時,ExecSql或OPEN都會返回受影響記錄的數量,但它總是返回-1,但始終爲-1。 我使用最新版本的psqlODBC:09.01.0200。使用Delphi中的ADOquery對PostgresSql進行更新查詢的返回代碼

代碼:

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

結果是-1

+0

你爲什麼不只是使用普通的'Insert'和'POST'機制? –

+0

也許背後沒有DBAware控件? – pf1957

+0

如果在調用「Adoquery1.ExecSQL」之後會發生什麼情況,您將添加'AdoQuery1.Close; AdoQuery1.SQL.Text:='SELECT nummer,naam FROM testtabel where nummer = 3 and naam =''Barnsten''); AdoQuery1.Open; ShowMessage('Result:'+ IntToStr(ADOQuery1.RowCount));'?你有'1'嗎?如果沒有,INSERT失敗,並且從RowsAffected獲得的值是正確的。 'Open'不使用'RowsAffected';它使用'RowCount'代替IIRC。 –

回答

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

返回我3