Forum > Databases

EZDatabaseError with postgres

(1/2) > >>

Root2:
I am trying to save data to postgres from tedit the code I am using is this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button3Click(Sender: TObject);begin  ZQuery1.Close;  ZQuery1.SQL.Clear;  ZQuery1.SQL.Add('insert into tdatostag (dirtag,valortagint,valortagnum,nombretag,tipodato)');  ZQuery1.SQL.Add('values (:dirtag,:valortagint,:valortagnum,:nombretag,:tipodato)');  ZQuery1.Params.ParamByName('dirtag').AsString:=Edit1.Text;  ZQuery1.Params.ParamByName('valortagint').AsString:=Edit2.Text;  ZQuery1.Params.ParamByName('valortagnum').AsString:=Edit3.Text;  ZQuery1.Params.ParamByName('nombretag').AsString:=Edit4.Text;  ZQuery1.Params.ParamByName('tipodato').AsString:=Edit5.Text;  ZQuery1.ExecSQL;  ZQuery1.Open;end;   
When compiling it does not give me any error, but when I press on the save button it gives me error:

The project has thrown an exception 'EZDatabaseError' with the message: Can not open a Resulset.

Structure of table.
dirtag      int4      not null
valortagint   int4      not null
valortagnum   numeric   not null
nombretag   bpchar   not null
tipodato           bpchar   not null

Thank you very much for your kind attention.

Regards.

marcov:
It seems to be a bug but you can work around it by using a returning statement. See

https://sourceforge.net/p/zeoslib/tickets/492/

dseligo:
Just comment out line 13:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// ZQuery1.Open;

Zvoni:
You're trying to Open a ZQuery, which underlyings SQL-Command is an Insert.....
Now what's wrong with that?

gucao:
I guess you need to return the generated data, do like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button3Click(Sender: TObject);begin  ZQuery1.Close;  ZQuery1.SQL.Clear;  ZQuery1.SQL.Add('insert into tdatostag (dirtag,valortagint,valortagnum,nombretag,tipodato)');  ZQuery1.SQL.Add('values (:dirtag,:valortagint,:valortagnum,:nombretag,:tipodato)');  ZQuery1.SQL.Add('RETURNING *'); //<<----add this line  ZQuery1.Params.ParamByName('dirtag').AsString:=Edit1.Text;  ZQuery1.Params.ParamByName('valortagint').AsString:=Edit2.Text;  ZQuery1.Params.ParamByName('valortagnum').AsString:=Edit3.Text;  ZQuery1.Params.ParamByName('nombretag').AsString:=Edit4.Text;  ZQuery1.Params.ParamByName('tipodato').AsString:=Edit5.Text;  //ZQuery1.ExecSQL; //<<----delete this line  ZQuery1.Open;end;  Please do not forget commit.

Navigation

[0] Message Index

[#] Next page

Go to full version