Is there any downside to passing a recordset to functions instead of individual variables?

无人久伴 提交于 2019-12-20 04:53:24

问题


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?


回答1:


Short Answer

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.

Analysis

  • 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.


来源:https://stackoverflow.com/questions/18754753/is-there-any-downside-to-passing-a-recordset-to-functions-instead-of-individual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!