syb_nsql 与 Perl 中的执行调用
我正在尝试使用 DBD::Sybase 查询 Sybase 数据库。有人可以澄清一下使用 syb_nsql 与prepare(. ..) - 执行(..) 调用?
I am trying to query Sybase database using DBD::Sybase. Can someone please clarify what is the difference between using syb_nsql vs prepare(...) - execute(..) calls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
syb_nsql(作为 的直接端口Sybase::DBlib 的
nsql
(它是一个相当高级的包装器)支持 DBD::Sybase 的准备执行 (IIRC) 本身不具备的所有 nsql 高级功能,您可以使用这些功能必须自己编写包装器代码(基本上,您几乎必须重新实现自己的 nsql 版本):MaxRows 功能限制返回行数以节省内存使用
可选的死锁重试逻辑
错误检查(使用其伴随错误和消息处理程序 - 我不记得了DBD::Sybase 有消息处理程序)
以及几个选项返回值的格式。
此外,数据可以批量返回给调用者(因此无需为 fetch_arrayref 等编写自己的循环),也可以通过作为参数传递的回调子例程逐行处理(此功能与 r_sql() 方法类似)。
考虑到nsql实际上是使用prepare/execute/fetchrow_arrayref实现的;它与您直接使用的任何正常准备执行功能几乎没有功能差异。它似乎甚至根据代码注释支持占位符,尽管它似乎没有记录。
所以区别在于,nsql 允许您避免滚动自己的包装器代码来支持上面列出的任何高级功能,例如死锁重试或 MaxRows。
syb_nsql (as a direct port of Sybase::DBlib's
nsql
which is a fairly high level wrapper) supports all of the nsql's advanced functionality which DBD::Sybase's prepare-execute does not (IIRC) have natively and for which you have to write the wrapper code yourself (basically, you pretty much have to re-implement your own version of nsql anyway):MaxRows functionality to limit the # of returned rows to conserve memory usage
optional deadlock retry logic
error checking (using its companion error and message handlers - I don't recall DBD::Sybase having message handlers)
and several options for the format of the return values.
In addition, the data can either be returned to the caller in bulk (thus no need to write your own loop for fetch_arrayref etc...), or processes line by line via a callback subroutine passed as an argument (this functionality is similar to the r_sql() method).
Considering the fact that nsql is actually implemented using prepare/execute/fetchrow_arrayref; it will pretty much have no functional difference from any normal prepare-execute functionality you use directly. It seems to even support placeholders as per the code comments though it doesn't appear to be documented.
So the difference is that nsql allows you to avoid rolling your own wrapper code to support any of the advanced features like deadlock retry or MaxRows that are listed above.