开发者

delete data in a table using delphi webservice

I have this problem regarding my program in delphi. I want to delete data in the table with this request url: http://localhost:8001/delete/woodSpecie?json={"SessionID":"MVykZKX31d19dYnywxsXM1MdPy0U7VW8","wood_specie_id":"80"}

I am creating a web service actually.

the following is my delphi code:

dm.SessionValidate(SessionID);

dshWoodSpecie := TDSHandlerWoodSpecie.Create(nil, dm);

try
  if dshWoodSpecie.Dataset.isEmpty then
    raise Exception.Create('Wood Specie table is empty.')
  els开发者_运维技巧e
  begin
    if Params.Field['wood_specie_id'] = nil then
    begin
      raise Exception.Create('Wood Specie ID is empty.');
    end
    else
    begin
      dshWoodSpecie.AddFilter('wood_specie_id', sqlcmprEqual,
        Params.Field['wood_specie_id'].Value);
    end;
    dshWoodSpecie.ExecSQLWhereHaving;
    dshWoodSpecie.Delete;
    dshWoodSpecie.ApplyUpdates;
  end;
finally
  dshWoodSpecie.Free;
end;

What happend is that it would return this error message :

-
error: {
    msg: "Server Error: Wood Specie table is empty."
    class: "EDatabaseError"
}

I really don't know what went wrong. I cannot delete and my table is not empty in the first place. And also, I wasn't able to see all my exceptions.


From your question it's impossible to say why your table might be empty, but my hunch is that webService calls are stateless and you think you're accessing an instance of the dataset that is out of scope in the context of your call and you're getting a new empty instance instead.

You should trace into 'dshWoodSpecie := TDSHandlerWoodSpecie.Create(nil, dm);' and check your the state of your instances at runtime.

As for debugging: if you are running a web Debug app you can trace just like with any exe - but if you're running in a real webserver (ie IIS) then build your webservice DLL in the virtual directory itself, launch the webservice processs and then attach to it using run->attach to process.

If you need more info on how to debug, please tell us what version of Delphi you're running and how you are deploying your webService.

"I wasn't able to see all my exceptions"

What do you mean? You saw the one exception that you should have seen if your dataset is empty - once that exception is thrown and not handled (as in your code) there's nothing more to see - your call stack terminates with the first unhandled expection.

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜