From 349ec7192ae1b0e3cee3247c4caefe6b43bf09c8 Mon Sep 17 00:00:00 2001 From: Thang Le Date: Wed, 29 Sep 2021 17:10:25 +1000 Subject: [PATCH] Propose fix for PostgresQL syntax error Change single quote ' to double quote " for labelList[$seriesKey] --- src/api/TotalCircleController.php | 20 ++++++++++---------- src/api/TotalRecordsController.php | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/api/TotalCircleController.php b/src/api/TotalCircleController.php index b3d767e..e6cd9ff 100644 --- a/src/api/TotalCircleController.php +++ b/src/api/TotalCircleController.php @@ -28,9 +28,9 @@ public function handle(NovaRequest $request) $calculation = isset($request->options) ? json_decode($request->options, true)['sum'] ?? 1 : 1; $request->validate(['model' => ['bail', 'required', 'min:1', 'string']]); $model = $request->input('model'); - $modelInstance = new $model; - $tableName = $modelInstance->getConnection()->getTablePrefix() . $modelInstance->getTable(); - $xAxisColumn = $request->input('col_xaxis') ?? DB::raw($tableName.'.created_at'); + $modelInstance = new $model; + $tableName = $modelInstance->getConnection()->getTablePrefix() . $modelInstance->getTable(); + $xAxisColumn = $request->input('col_xaxis') ?? DB::raw($tableName.'.created_at'); $cacheKey = hash('md4', $model . (int)(bool)$request->input('expires')); $dataSet = Cache::get($cacheKey); if (!$dataSet) { @@ -45,7 +45,7 @@ public function handle(NovaRequest $request) $filter = $seriesData->filter; $labelList[$seriesKey] = $seriesData->label; if(empty($filter->value)&&isset($filter->operator)&&($filter->operator=='IS NULL' || $filter->operator=='IS NOT NULL')) { - $seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".$filter->operator." then ".$calculation." else 0 end) as '".$labelList[$seriesKey]."'"; + $seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".$filter->operator." then ".$calculation." else 0 end) as \"".$labelList[$seriesKey]."\""; } else if(empty($filter->value)){ $seriesSql .= ", SUM(CASE WHEN "; $countFilter = count($filter); @@ -53,9 +53,9 @@ public function handle(NovaRequest $request) $seriesSql .= " ".$listFilter->key." ".($listFilter->operator ?? "=")." '".$listFilter->value."' "; $seriesSql .= $countFilter-1 != $keyFilter ? " AND " : ""; } - $seriesSql .= "then ".$calculation." else 0 end) as '".$labelList[$seriesKey]."'"; + $seriesSql .= "then ".$calculation." else 0 end) as \"".$labelList[$seriesKey]."\""; } else { - $seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".($filter->operator ?? "=")." '".$filter->value."' then ".$calculation." else 0 end) as '".$labelList[$seriesKey]."'"; + $seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".($filter->operator ?? "=")." '".$filter->value."' then ".$calculation." else 0 end) as \"".$labelList[$seriesKey]."\""; } } } @@ -66,7 +66,7 @@ public function handle(NovaRequest $request) } else { $query = $model::selectRaw('SUM('.$calculation.') counted'.$seriesSql); } - + if(is_numeric($advanceFilterSelected)){ $query->where($xAxisColumn, '>=', Carbon::now()->subDays($advanceFilterSelected)); } @@ -82,7 +82,7 @@ public function handle(NovaRequest $request) else if($dataForLast != '*') { $query->where($xAxisColumn, '>=', Carbon::now()->firstOfMonth()->subMonth($dataForLast-1)); } - + if(isset(json_decode($request->options, true)['queryFilter'])){ $queryFilter = json_decode($request->options, true)['queryFilter']; foreach($queryFilter as $qF){ @@ -134,6 +134,6 @@ public function handle(NovaRequest $request) 'xAxis' => $xAxis, 'yAxis' => $yAxis ] - ]); + ]); } -} \ No newline at end of file +} diff --git a/src/api/TotalRecordsController.php b/src/api/TotalRecordsController.php index 8a07433..70ae545 100644 --- a/src/api/TotalRecordsController.php +++ b/src/api/TotalRecordsController.php @@ -53,7 +53,7 @@ public function handle(NovaRequest $request) $filter = $seriesData->filter; $labelList[$seriesKey] = $seriesData->label; if(empty($filter->value)&&isset($filter->operator)&&($filter->operator=='IS NULL' || $filter->operator=='IS NOT NULL')) { - $seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".$filter->operator." then ".$calculation." else 0 end) as '".$labelList[$seriesKey]."'"; + $seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".$filter->operator." then ".$calculation." else 0 end) as \"".$labelList[$seriesKey]."\""; } else if(empty($filter->value)){ $seriesSql .= ", SUM(CASE WHEN "; $countFilter = count($filter); @@ -61,9 +61,9 @@ public function handle(NovaRequest $request) $seriesSql .= " ".$listFilter->key." ".($listFilter->operator ?? "=")." '".$listFilter->value."' "; $seriesSql .= $countFilter-1 != $keyFilter ? " AND " : ""; } - $seriesSql .= "then ".$calculation." else 0 end) as '".$labelList[$seriesKey]."'"; + $seriesSql .= "then ".$calculation." else 0 end) as \"".$labelList[$seriesKey]."\""; } else { - $seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".($filter->operator ?? "=")." '".$filter->value."' then ".$calculation." else 0 end) as '".$labelList[$seriesKey]."'"; + $seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".($filter->operator ?? "=")." '".$filter->value."' then ".$calculation." else 0 end) as \"".$labelList[$seriesKey]."\""; } } } @@ -75,7 +75,7 @@ public function handle(NovaRequest $request) } else { $query = $model::selectRaw('DATE('.$xAxisColumn.') AS cat, DATE('.$xAxisColumn.') AS catorder, sum('.$calculation.') counted'.$seriesSql); } - + if(is_numeric($advanceFilterSelected)){ $query->where($xAxisColumn, '>=', Carbon::now()->subDays($advanceFilterSelected)); } @@ -110,7 +110,7 @@ public function handle(NovaRequest $request) $query = $model::selectRaw('YEARWEEK('.$xAxisColumn.', '.$startWeek.') AS cat, YEARWEEK('.$xAxisColumn.', '.$startWeek.') AS catorder, sum('.$calculation.') counted'.$seriesSql); } } - + if(is_numeric($advanceFilterSelected)){ $query->where($xAxisColumn, '>=', Carbon::now()->subDays($advanceFilterSelected)); } @@ -172,7 +172,7 @@ public function handle(NovaRequest $request) $query = $model::selectRaw('DATE_FORMAT('.$xAxisColumn.', "%b %Y") AS cat, DATE_FORMAT('.$xAxisColumn.', "%Y-%m") AS catorder, sum('.$calculation.') counted'.$seriesSql); } } - + if(is_numeric($advanceFilterSelected)){ $query->where($xAxisColumn, '>=', Carbon::now()->subDays($advanceFilterSelected)); } @@ -191,7 +191,7 @@ public function handle(NovaRequest $request) $query->groupBy('catorder', 'cat') ->orderBy('catorder', 'asc'); } - + if(isset(json_decode($request->options, true)['queryFilter'])){ $queryFilter = json_decode($request->options, true)['queryFilter']; foreach($queryFilter as $qF){ @@ -264,9 +264,9 @@ public function handle(NovaRequest $request) 'xAxis' => $xAxis, 'yAxis' => $yAxis ] - ]); + ]); } - + private function counted($dataSet, $bgColor = "#111", $type = "bar", $label = "Total") { $yAxis = [