phpMyAdmin使用用户定义的变量表现不佳

时间:2016-09-07 08:35:52

标签: mysql phpmyadmin

这只是为了报告phpMyAdmin中的SQL查询面板的一些不良行为(phpMyAdmin 4.0.10.14)。

我有一个包含三条记录的User表。 ID为2,3和4。 我跑了这个:

SET @IDS = 'xxx';
SELECT @IDS := CONCAT(@IDS," ",id) FROM User;

得到了这个:

@IDS := CONCAT(@IDS," ",id)
xxx 2 3 4 2 3 4 2
xxx 2 3 4 2 3 4 2 3
xxx 2 3 4 2 3 4 2 3 4

显然,在第三次运行以准备结果集之前,select实际上是静默运行了两次。每次运行它都会在@IDS中累积ID。我用' xxx'初始化了@IDS。只是为了让所有的ID都来自一个查询。我已经看到数字用户定义得到奇怪值的其他问题,但无法将其固定下来。这个测试更清楚地表明存在问题。

但它变得更奇怪了。我跑了这个:

SET @IDS = 'xxx';
SELECT ids INTO @RESULT FROM
(SELECT @IDS := CONCAT(@IDS," ",id) as ids FROM User limit 1) AS HG;
SELECT @RESULT;

SET @IDS = 'xxx';
SELECT @IDS := CONCAT(@IDS," ",id) as ids FROM User;

得到了这个:

@RESULT
xxx 2

ids 
xxx 2 3 4 2
xxx 2 3 4 2 3
xxx 2 3 4 2 3 4

然后我跑了

SET @IDS = 'xxx';
SELECT @IDS := CONCAT(@IDS," ",id) as ids FROM User;

SET @IDS = 'xxx';
SELECT ids INTO @RESULT FROM
(SELECT @IDS := CONCAT(@IDS," ",id) as ids FROM User limit 1) AS HG;
SELECT @RESULT;

得到了

ids
xxx 2 2 3 4 2
xxx 2 2 3 4 2 3
xxx 2 2 3 4 2 3 4

@RESULT 
xxx 2

然后这个

SET @IDS = 'xxx';
SELECT @IDS := CONCAT(@IDS," ",id) FROM User;

SET @IDS = 'xxx';
SELECT @IDS := CONCAT(@IDS," ",id) as ids FROM User;

给了我

@IDS := CONCAT(@IDS," ",id)
xxx 2 3 4 2
xxx 2 3 4 2 3
xxx 2 3 4 2 3 4

ids 
xxx 2 3 4 2 3 4 2
xxx 2 3 4 2 3 4 2 3
xxx 2 3 4 2 3 4 2 3 4

道德:在这种环境中不要使用用户定义的变量。

0 个答案:

没有答案