Skip to content

Commit

Permalink
Merge pull request #36 from ProcessMaker/bug/FOUR-12716
Browse files Browse the repository at this point in the history
FOUR-12716: PMQL "lower" function is not working correctly
  • Loading branch information
ryancooley authored Dec 8, 2023
2 parents 598ce3c + 45c2f7a commit d209802
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/Exceptions/UnsupportedQueryGrammarException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace ProcessMaker\Query\Exceptions;

use Exception;

class UnsupportedQueryGrammarException extends Exception
{
public function __construct(
$message = 'Unsupported query grammar for handling JSON fields.',
$code = 0,
Exception $previous = null
) {
parent::__construct($message, $code, $previous);
}
}
8 changes: 7 additions & 1 deletion src/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public function field()
{
$params = [];
foreach ($this->params as $param) {
$params[] = $param->toEloquent();
$eloquentParam = $param->toEloquent();
if (is_object($eloquentParam)) {
$grammar = DB::connection()->getQueryGrammar();
$eloquentParam = $eloquentParam->getValue($grammar);
}

$params[] = $eloquentParam;
}

return $this->name . '(' . implode(',', $params) . ')';
Expand Down
4 changes: 2 additions & 2 deletions src/JsonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ProcessMaker\Query;

use Exception;
use Illuminate\Database\Query\Grammars\MySqlGrammar;
use Illuminate\Database\Query\Grammars\SQLiteGrammar;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Query\Exceptions\UnsupportedQueryGrammarException;

class JsonField extends BaseField
{
Expand All @@ -29,7 +29,7 @@ public function toEloquent($connection = null)
} elseif (is_a($grammar, SQLiteGrammar::class)) {
return $connection->raw((new \ProcessMaker\Query\Grammars\SQLiteGrammar)->wrapJsonSelector($value));
} else {
throw new Exception('Unsupported query grammar for handling JSON fields.');
throw new UnsupportedQueryGrammarException();
}
}
}

0 comments on commit d209802

Please sign in to comment.