Skip to content

Commit

Permalink
JSON_EXTRACT to extended MySQL dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioviana authored and sergeyklay committed Nov 6, 2018
1 parent 995d5b5 commit ce8e8ec
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Library/Phalcon/Db/Dialect/MysqlExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ public function getSqlExpression(array $expression, $escapeChar = null, $bindCou
return $this->getSqlExpression($expression['arguments'][0]) .
' REGEXP (' . $this->getSqlExpression($expression['arguments'][1]) . ')';
break;

case 'JSON_EXTRACT':
if (count($expression["arguments"]) < 2) {
throw new Exception('JSON_EXTRACT requires 2 parameters');
}

$arguments = [];
$length = count($expression["arguments"]);
for ($i = 0; $i < $length; $i++) {
$arguments[] = $i === 0 ?
$this->getSqlExpression($expression["arguments"][$i]) :
$expression["arguments"][$i]['value'];
}

return 'JSON_EXTRACT(' . join(', ', $arguments) . ')';
break;
}
}

Expand Down

0 comments on commit ce8e8ec

Please sign in to comment.