gpt4 book ai didi

Postgresql ColdFusion CFQuery block

转载 作者:行者123 更新时间:2023-11-29 11:25:25 27 4
gpt4 key购买 nike

我是 ColdFusion 的新手,我在 CFQuery 中写了一段 Postgres 代码:

<cffunction name="insertToReport" access="private" returntype="struct" output="false" >

<cfset var xyz = structNew() >
<cfset xyz.code = "">
<cfquery name="querysampleresult" datasource="abc">
DO
$BODY$
DECLARE resultValue int;
BEGIN
resultValue = 1;
SELECT resultValue INTO resultValue ;
END;
$BODY$
</cfquery>

<cfset xyz.code = querysampleresult.resultValue >

<cfreturn xyz >
</cffunction>

我的问题是我无法访问 CFQuery 标记之外的变量 resultValue,即它抛出异常:

Element RESULTVALUE is undefined in querysampleresult

这发生在函数末尾的 CFSet 语句中:

<cfset xyz.code = querysampleresult.resultValue  >

我不知道如何在结构中设置变量 resultValue,我必须从这里向调用环境返回一个结构。请帮助我,在此先感谢。

最佳答案

将另一个选择语句添加到选择结果值的查询中。现在您正在选择 INTO 表,它不返回查询。

<cffunction name="insertToReport" access="private" returntype="struct" output="false" >
<cfargument name="rptDataObj" required="yes" type="com.certain.register123.data.reportData" hint="The affected report.">
<cfargument name="maxColumns" type="numeric" required="false" default="10" hint="The maximum number of active columns that should be saved to the report. " ><!--- As of REG-559 20060215, the default was 10 --->
<cfargument name="dsn" type="string" required="false" default="#application.portals.data[request.applicationName].dsn#" >
<cfset var uiCustomColumn = queryNew("") >
<cfset var strSaveError = structNew() >
<cfset strSaveError.code = 0 >
<cfset strSaveError.message = "">
<cfset strSaveError.udcId = "">


<cfquery name="uiCustomColumn" datasource="#arguments.dsn#">
DO
$BODY$
DECLARE resultValue int;
DECLARE nextId bigint;
DECLARE maxColumns bigint;
DECLARE udcReportId bigint; /*Have to use this value more than once, so declare it to reduce number of parameters*/
DECLARE udcOrder int; /*Have to use this value more than once, so declare it to reduce number of parameters*/

BEGIN
udcReportId = #arguments.rptDataObj.getId()# ;
maxColumns = #arguments.maxColumns# ;

IF (( select count( udc_id ) from user_defined_column WHERE udc_frn_rpt_id = udcReportId AND udc_is_active = true ) >= maxColumns) THEN
BEGIN
resultValue = 1; /*There isn't an available slot for this column */
END;
ELSE
BEGIN

nextId = (SELECT coalesce( MAX(udc_id), 0 ) FROM user_defined_column ) + 1 ;
udcOrder = (SELECT coalesce( MAX(udc_order), 0 ) FROM user_defined_column WHERE udc_frn_rpt_id = udcReportId AND udc_is_active = true ) + 1 ;

INSERT INTO user_defined_column(
udc_id
,udc_frn_rpt_id
,udc_label
,udc_data
,udc_type
,udc_order
,udc_is_active
,udc_date_created
,udc_date_modified
)
VALUES(
nextId
,udcReportId
,'hi'
,'hi'
,12
,udcOrder
,true
,now()
,now()
);


resultValue = 0;
END ;
END IF;
SELECT resultValue, nextId INTO resultValue /*Set a success result */
, nextId;

SELECT resultValue;

END;
$BODY$
</cfquery>

<cfset strSaveError.code = uiCustomColumn.resultValue >
<cfset strSaveError.udcId = uiCustomColumn.nextId >

<cfreturn strSaveError >

关于Postgresql ColdFusion CFQuery block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14561620/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com