Skip to content

Commit

Permalink
make field pattern more generic, #60
Browse files Browse the repository at this point in the history
  • Loading branch information
ikkez committed Feb 22, 2018
1 parent 3f95972 commit 05ccecb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/db/cortex.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ protected function filteredFind($filter = NULL, array $options = NULL, $ttl = 0,
$qtable = $this->db->quotekey($this->table);
if (isset($options['order']) && $this->db->driver() == 'pgsql')
// PostgreSQLism: sort NULL values to the end of a table
$options['order'] = preg_replace('/\h+DESC/i',' DESC NULLS LAST',$options['order']);
$options['order'] = preg_replace('/\h+DESC(?=\s*(?:$|,))/i',' DESC NULLS LAST',$options['order']);
if ($hasJoin) {
// assemble full sql query
$adhoc='';
Expand Down Expand Up @@ -2625,7 +2625,10 @@ public function prepareOptions($options, $engine, $db) {
if (array_key_exists('order', $options) &&
FALSE===strpos($options['order'],$char))
$options['order']=preg_replace_callback(
'/(\w+\h?\(|(?:DESC|ASC)(?:\s+\w+)*)|(\b\d?[a-zA-Z_](?:[\w\-.])*)/i',
'/(\w+\h?\(|'. // skip function names
'\b(?!\w+)(?:\s+\w+)+|' . // skip field args
'\)\s+\w+)|'. // skip function args
'(\b\d?[a-zA-Z_](?:[\w\-.])*)/i', // match table/field keys
function($match) use($db) {
if (!isset($match[2]))
return $match[1];
Expand Down

0 comments on commit 05ccecb

Please sign in to comment.