将记录集传递给函数而不是单个变量有任何不利之处吗? [英] Is there any downside to passing a recordset to functions instead of individual variables?

查看:86
本文介绍了将记录集传递给函数而不是单个变量有任何不利之处吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个单用户Access 2007数据库,该数据库执行诸如发送报告和更新计时器上的其他数据库(事件")之类的操作-一次一个事件.执行每个事件时,将创建一个单行记录集,其中包含该事件需要运行的信息.我一直在使用单个变量以通常的方式将参数传递给函数,但是我想知道是否将整个事件记录集传递给每个函数并使用该函数所需的一切是否有意义.再次考虑到,这是一个单用户数据库,每天只有大约250个事件,这有什么不利之处吗?

We have a single-user Access 2007 database that does things like send reports and update other databases on a timer ("events") -- one event at a time. As each event is executed, a one-row recordset is created with information that the event needs to run. I've been passing parameters to functions the usual way using individual variables but I'm wondering if would make sense to just pass the entire event recordset to each function and use whatever is needed for that function. Considering that, again, this is a single-user database and there are only about 250 events per day, is there any downside to this?

推荐答案

简短回答

在公开的上下文中,将记录集(作为引用)传递给函数没有任何不利之处. 这可能是好事,也可能是坏事,这取决于您的总体设计,产品周期等.

In the exposed context, there is no downside to passing the recordset (as reference) to functions. This can be a good or bad thing depending on your overall design, product cycle, etc.

分析

  • 内存分配:Recordset对象将分配更长的时间;但不会使用更多的内存.所以没有缺点.
  • speed:由于您不必将记录集中的数据复制到变量中,因此这可能是一种改进-如果处理的数据量很大,例如数组.
  • 锁定数据库:如果没有并发进程,则不会发生冲突.对于并发进程,只要Recordset为只读,就不会发生冲突.
  • 数据一致性(如果打开Recordset时数据库内容发生更改,会发生什么情况)? DBMS确保数据一致性.根据是否要使更改反映在Recordset中,将其作为动态集或快照打开(
  • memory allocation : the Recordset object will be allocated for a longer time ; but will not use more memory. So no downside.
  • speed : As you won't have to copy the data from the recordset to variables, this could be an improvement - if working with big data amount, such as arrays.
  • locking the database : if no concurrent processes, there is no possible conflict. With concurrent processes, there is no conflict as long as Recordset are readonly.
  • data consistency (what happens if the database contents change while a Recordset is open) ? Data consistency is ensured by the DBMS. Depending if you want the changes to be reflected in the Recordset or not, open it as dynaset or snapshot (see also MSDN). To keep same behavior as now, it should be snapshot type.
  • interface design : The API of your functions would be more flexible - less sensitive to changes in the DB structure. Telling if this is a good thing or a downside ... well, is context-dependant and opinion-based.

这篇关于将记录集传递给函数而不是单个变量有任何不利之处吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆