【问题标题】:How to get the results of a stored procedure when using cfscript new StoredProc()使用 cfscript new StoredProc() 时如何获取存储过程的结果
【发布时间】:2019-03-14 15:30:16
【问题描述】:

第一次尝试通过 cfscript 使用存储过程,但我不知道如何获得结果。通过常规查询,我会执行以下操作来获取结果集:

queryResult = queryResult.execute().getResult();

使用存储过程,我的代码是:

queryResult = new storedProc( procedure = 'stpQueryMyResultSet', datasource = 'mydsn' );
queryResult = queryResult.execute();
writeDump(queryResult);

返回 3 个结构 - prefixprocResultSetsprocOutVariables,但我似乎无法弄清楚如何获取查询结果。

【问题讨论】:

  • The documentationgetProcResultSets():访问过程返回的结果集。转储 procResultsSets 键,它可能包含查询对象的数组或结构。
  • 您可以在存储过程中处理大量业务逻辑,否则您可能会尝试在应用程序代码中复制这些逻辑。 sprocs 的好处之一是,如果您需要,它们可以返回多个结果集,但您必须在 CF 中稍微不同地处理它们。

标签: coldfusion coldfusion-10 cfml


【解决方案1】:

感谢@Ageax 将我指向该页面。这是我如何让它工作的(我还添加了一个参数以返回最大行数):

queryResult = new storedProc( procedure = 'stpQueryMyResultSet', datasource = 'mydsn' );
queryResult.addParam( type = 'in', cfsqltype = 'cf_sql_integer', value = '10');
queryResult.addProcResult( name = 'result' );
qResult = queryResult.execute().getProcResultSets().result;

writeDump(qResult);

【讨论】:

  • RE:我在上面的评论:如果你有多个结果集,你可以像.addProcResult(name='result', resultset=1) .addProcResult(name='result2', resultset=2)一样指定它们
  • 然后将它们称为:qResult=queryResult.execute().getProcResultSets() 然后 qResult.resultqResult.result2
猜你喜欢
  • 2017-06-22
  • 1970-01-01
  • 1970-01-01
  • 2011-07-24
  • 2014-02-07
  • 2017-08-01
  • 2020-10-23
相关资源
最近更新 更多