[英]Prestashop SQL Manager GROUP BY date
我正在Prestashop中為SQL管理器編寫一些查詢。
我想按月分組:
SELECT AVG(total_products)
FROM ps_order_invoice
GROUP BY YEAR(delivery_date), MONTH(delivery_date)
但是SQL Manager拒絕保存它,僅顯示消息“錯誤”。
除了僅接受SELECT
查詢,我找不到有關SQL Manager限制的更多信息。
但是,如果刪除YEAR
和MONTH
函數,則可以保存查詢。
注意:不幸的是,我無權訪問phpmyadmin
我安裝了新的prestashop-1.6.0.6,並能夠得到您的錯誤。 檢查代碼后,我發現問題來自RequestSql類。
cutAttribute方法無法解析“ YEAR(delivery_date)”之類的屬性。 它返回一個類似於“ YEARdelivery_date”的字符串,而不是“ delivery_date”。
要解決此問題,您可以覆蓋此類,並使用最新的prestashop版本中的cutAttribute方法。
創建一個名為“ RequestSql.php”的文件,該文件位於“ override / classes”中,內容如下:
class RequestSql extends RequestSqlCore
{
/**
* Cut an attribute with or without the alias
*
* @param $attr
* @param $from
* @return array|bool
*/
public function cutAttribute($attr, $from)
{
$matches = array();
if (preg_match('/((`(\()?([a-z0-9_])+`(\))?)|((\()?([a-z0-9_])+(\))?))\.((`(\()?([a-z0-9_])+`(\))?)|((\()?([a-z0-9_])+(\))?))$/i', $attr, $matches, PREG_OFFSET_CAPTURE)) {
$tab = explode('.', str_replace(array('`', '(', ')'), '', $matches[0][0]));
if ($table = $this->returnNameTable($tab[0], $from)) {
return array(
'table' => $table,
'alias' => $tab[0],
'attribut' => $tab[1],
'string' => $attr
);
}
} elseif (preg_match('/((`(\()?([a-z0-9_])+`(\))?)|((\()?([a-z0-9_])+(\))?))$/i', $attr, $matches, PREG_OFFSET_CAPTURE)) {
$attribut = str_replace(array('`', '(', ')'), '', $matches[0][0]);
if ($table = $this->returnNameTable(false, $from, $attr)) {
return array(
'table' => $table,
'attribut' => $attribut,
'string' => $attr
);
}
}
return false;
}
}
並刪除文件“ cache / class_index.php”,否則將找不到替代項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.