make sql statement work for mysql and sqlite

This commit is contained in:
Uwe Steinmann 2014-04-08 15:28:13 +02:00
parent 151c3dd8f2
commit 9da9b10b88

View File

@ -2073,14 +2073,14 @@ class SeedDMS_Core_DMS {
return $resArr;
case 'docspermonth':
$queryStr = "select `key`, count(`key`) as total from (select from_unixtime(date, '%Y-%m') as `key`from tblDocuments) a group by `key` order by `key`";
$queryStr = "select `key`, count(`key`) as total from (select ".$this->db->getDateExtract("date")." as `key` from tblDocuments) a group by `key` order by `key`";
$resArr = $this->db->getResultArray($queryStr);
if (!$resArr)
return false;
return $resArr;
case 'docsaccumulated':
$queryStr = "select `key`, count(`key`) as total from (select from_unixtime(date, '%Y-%m-%d') as `key`from tblDocuments) a group by `key` order by `key`";
$queryStr = "select `key`, count(`key`) as total from (select ".$this->db->getDateExtract("date")." as `key` from tblDocuments) a group by `key` order by `key`";
$resArr = $this->db->getResultArray($queryStr);
if (!$resArr)
return false;
@ -2088,7 +2088,12 @@ class SeedDMS_Core_DMS {
$sum = 0;
foreach($resArr as &$res) {
$sum += $res['total'];
$res['key'] = mktime(12, 0, 0, substr($res['key'], 5, 2), substr($res['key'], 8, 2), substr($res['key'], 0, 4)) * 1000;
/* auxially variable $key is need because sqlite returns
* a key '`key`'
*/
$key = mktime(12, 0, 0, substr($res['key'], 5, 2), substr($res['key'], 8, 2), substr($res['key'], 0, 4)) * 1000;
unset($res['key']);
$res['key'] = $key;
$res['total'] = $sum;
}
return $resArr;