我在 Coldfusion8/MySQL 中调用存储过程,它从产品表中获取 3 种类型的最低和最高价格。
我在将临时表返回给 MySQL 时遇到问题。下面的代码只返回第一个foundMin值,而不是临时表本身。
如果我在 MySQL 中运行它,结果是
foundmin 1st price > returned to Coldfusion
foundmax 1st price
foundmin 2nd price
foundmax 2nd price
foundmin 3rd price
foundmax 3rd price
temporary table
因此,当我只想要表格时,我将返回所有单独的表格条目和表格。
这是我的代码:
BEGIN
DECLARE filterILN vARCHAR(100);
DECLARE localILN vARCHAR(100);
DECLARE orderILN vARCHAR(55);
#search strings
DECLARE p_e vARCHAR(55) DEFAULT 'art.preis_ek';
DECLARE p_a vARCHAR(55) DEFAULT 'art.preis_aktuell';
DECLARE p_r vARCHAR(55) DEFAULT 'art.rabatt';
DECLARE strLen INT DEFAULT 4;
DECLARE strCount INT DEFAULT 1;
DECLARE searchFor vARCHAR(55);
DECLARE foundMin DECIMAL(12,2);
DECLARE foundMax DECIMAL(12,2);
# temp table
DROP TEMPORARY TABLE IF EXISTS MinMax;
CREATE TEMPORARY TABLE MinMax (
price vARCHAR(50) DEFAULT ''
, minVal DECIMAL(12,2) DEFAULT 0.00
, maxVal DECIMAL(12,2) DEFAULT 0.00
) ENGINE=MEMORY;
# FILTER 1
IF param_reference_iln = 'A' THEN SET filterILN = 'B'
ELSEIF param_reference_iln = 'C' THEN SET filterILN = 'D'
END IF;
# FILTER 2
IF param_filter IS NOT NULL AND param_filter != ""
THEN SET localILN = CONCAT('AND (iln = "', param_filter, '")');
ELSE SET localILN = '*';
END IF;
# FILTER 3
IF param_preorder = 'ja'
THEN SET orderILN = CONCAT('AND vororder = "',param_preorder, '"');
ELSE SET orderILN = '*';
END IF;
#loop over strIDs
getPrice:
LOOP
IF ELT(strCount, p_e, p_a, p_r) = 'art.rabatt'
THEN SET searchFor = 'art.preis_ek - art.preis_aktuell)/art.preis_ek';
ELSE SET searchFor = ELT(strCount, p_e, p_a, p_r);
END IF;
#min
SELECT MIN(searchFor) AS foundMin
FROM artikelstammdaten AS art
WHERE art.aktiv = "ja"
AND art.bestand != "0"
AND filterILN
AND art.modus = CONCAT('OPEN ', param_unlocked_iln)
AND localILN
AND orderILN
LIMIT 1;
#max
SELECT MAX(searchFor) AS foundMax
FROM artikelstammdaten AS art
WHERE art.aktiv = "ja"
AND art.bestand != "0"
AND filterILN
AND art.modus = CONCAT('OPEN ', param_unlocked_iln)
AND localILN
AND orderILN
LIMIT 1;
# insert into temp table
INSERT INTO MinMax ( price, minVal, maxVal )
VALUES( ELT(strCount, p_e, p_a, p_r), foundMin, foundMax );
# increate counter by 1, end if strLen reached
SET strCount = strCount+1;
IF strCount = strLen
THEN LEAVE getPrice;
END IF;
END LOOP getPrice;
#output table
SELECT * FROM MinMax;
#destroy
DROP TABLE MinMax;
END
这些值被正确计算,并且也插入到它们应该在的临时表中。唯一的问题是上面返回表条目和表。
问题:
如何将临时表作为结果集/结构返回,然后我可以在 Coldfusion 中使用它?