使用delphi webservice删除表中的数据

发布于 11-19 22:19 字数 1048 浏览 6 评论 0原文

我的delphi程序有这个问题。我想使用以下请求网址删除表中的数据:http://localhost:8001/delete/woodSpecie?json={"SessionID":"MVykZKX31d19dYnywxsXM1MdPy0U7VW8","wood_specie_id":"80"}

我实际上正在创建一个网络服务。

以下是我的delphi代码:

dm.SessionValidate(SessionID);

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

try
  if dshWoodSpecie.Dataset.isEmpty then
    raise Exception.Create('Wood Specie table is empty.')
  else
  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;

发生的事情是它会返回此错误消息:

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

我真的不知道出了什么问题。我无法删除,而且我的表首先不为空。 而且,我无法看到所有的例外情况。

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.')
  else
  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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从你的问题来看,不可能说出为什么你的表可能是空的,但我的预感是 webService 调用是无状态的,并且你认为你正在访问的数据集实例超出了你的调用上下文的范围,并且你而是获取一个新的空实例。

您应该跟踪“dshWoodSpecie := TDSHandlerWoodSpecie.Create(nil, dm);”并在运行时检查实例的状态。

至于调试:如果您正在运行 Web 调试应用程序,您可以像使用任何 exe 一样进行跟踪 - 但如果您在真实的 Web 服务器(即 IIS)中运行,则在虚拟中构建 Web 服务 DLL目录本身,启动 Web 服务进程,然后使用 run->attach to process 附加到它。

如果您需要有关如何调试的更多信息,请告诉我们您正在运行的 Delphi 版本以及如何部署您的 webService。

“我无法看到所有异常”

你是什么意思?如果数据集为空,您应该看到一个异常 - 一旦抛出该异常并且未处理(如您的代码中),就没有更多可看的 - 您的调用堆栈会因第一个未处理的期望而终止。

华泰

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文