[eluser]Morty[/eluser]
Here's more info, and a workaround (for the time being).
First you need to comment out the protect identifier function:
Code:
function _protect_identifiers($item, $first_word_only = FALSE)
{
/* if (is_array($item))
{
$escaped_array = array();
foreach($item as $k=>$v)
{
$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);
}
return $escaped_array;
}
// This function may get "item1 item2" as a string, and so
// we may need ""item1" "item2"" and not ""item1 item2""
if (ctype_alnum($item) === FALSE)
{
if (strpos($item, '.') !== FALSE)
{
$aliased_tables = implode(".",$this->ar_aliased_tables).'.';
$table_name = substr($item, 0, strpos($item, '.')+1);
$item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item;
}
// This function may get "field >= 1", and need it to return ""field" >= 1"
$lbound = ($first_word_only === TRUE) ? '' : '|\s|\(';
$item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item);
}
else
{
return "\"{$item}\"";
}
$exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS');
foreach ($exceptions as $exception)
{
if (stristr($item, " \"{$exception}\" ") !== FALSE)
{
$item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item);
}
} */
return $item;
Sample request when it's commented out:
Code:
SELECT ITMREF_0 AS PN, STOFCY_0 AS Site, LOC_0 AS Loc, FLOOR(SUM(QTYPCU_0)) AS qty FROM ARCEXPL.STOCK STK WHERE QTYPCU_0 <> 0 GROUP BY ITMREF_0, STOFCY_0, LOC_0 ORDER BY PN, Site, Loc
Code:
SELECT ITMREF_0 AS PN, STOFCY_0 AS Site, LOC_0 AS Loc, FLOOR(SUM(QTYPCU_0)) AS qty
FROM ARCEXPL.STOCK STK
WHERE (QTYPCU_0 <> 0)
GROUP BY ITMREF_0, STOFCY_0, LOC_0
ORDER BY PN, Site, Loc
This is the same request as corrected by SQL Server Enterprise.
Another one (sent by AR, then corrected by SQLSE):
Code:
SELECT STOSER.ITMREF_0 AS PN, STOSER.SERNUM_0 AS SN FROM ARCEXPL.STOSER STOSER WHERE STOSER.STOFCY_0 = 'LU1' AND BPCNUM_0 = '' AND STOSER.SERNUM_0 IN ('G063616667', 'E066316793')
Code:
SELECT ITMREF_0 AS PN, SERNUM_0 AS SN
FROM ARCEXPL.STOSER STOSER
WHERE (STOFCY_0 = 'LU1') AND (BPCNUM_0 = '') AND (SERNUM_0 IN ('G063616667', 'E066316793'))
And now what AR is doing wrong:
Code:
SELECT "ITMREF_0" AS "PN", "STOFCY_0" AS "Site", "LOC_0" AS "Loc", COUNT(*) AS NB FROM ARCEXPL.STOJOU WHERE IPTDAT_0 > '26/01/2008' GROUP BY "ITMREF_0", "STOFCY_0", "LOC_0"
It seems that field names are protected, and there is no need for it.
With workaround:
Code:
SELECT ITMREF_0 AS PN, STOFCY_0 AS Site, LOC_0 AS Loc, COUNT(*) AS NB FROM ARCEXPL.STOJOU WHERE IPTDAT_0 > '26/01/2008' GROUP BY ITMREF_0, STOFCY_0, LOC_0
Hope that'll help.