From ffd2d1b5f85dd3ad190d25734392fa158ebf911b Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 7 Mar 2017 12:24:42 -0700 Subject: [PATCH] * All apps - Add special search case for # to only match the ID, not search the whole entry --- api/src/Storage/Base.php | 9 +++++++++ infolog/inc/class.infolog_so.inc.php | 1 + 2 files changed, 10 insertions(+) diff --git a/api/src/Storage/Base.php b/api/src/Storage/Base.php index 70aa354a4d..fcddaab0da 100644 --- a/api/src/Storage/Base.php +++ b/api/src/Storage/Base.php @@ -1190,6 +1190,10 @@ class Base /** * Return criteria array for a given search pattern * + * We handle quoted text, wildcards and boolean operators (+/-, AND/OR). If + * the pattern is '#' followed by an integer, the search is limited to just + * the primary key. + * * @param string $_pattern search pattern incl. * or ? as wildcard, if no wildcards used we append and prepend one! * @param string &$wildcard ='' on return wildcard char to use, if pattern does not already contain wildcards! * @param string &$op ='AND' on return boolean operation to use, if pattern does not start with ! we use OR else AND @@ -1218,6 +1222,11 @@ class Base $numeric_types = array('auto', 'int', 'float', 'double', 'decimal'); $numeric_columns = array(); + // Special handling for an ID search, # + if(strpos($_pattern, '#') === 0 && is_numeric(substr($_pattern, 1))) + { + return array('(' . $this->table_name.'.'. $this->autoinc_id . '=' . (int)substr($_pattern,1) . ')'); + } if(!$search_cols) { $search_cols = $this->get_default_search_columns(); diff --git a/infolog/inc/class.infolog_so.inc.php b/infolog/inc/class.infolog_so.inc.php index 77c72ff660..6dc5f37336 100644 --- a/infolog/inc/class.infolog_so.inc.php +++ b/infolog/inc/class.infolog_so.inc.php @@ -811,6 +811,7 @@ class infolog_so $wildcard = $op = null; $so_sql = new Api\Storage\Base('infolog', $this->info_table, $this->db); + $so_sql->table_name = 'main'; $search = $so_sql->search2criteria($query['search'], $wildcard, $op, null, $columns); $sql_query = 'AND ('.(is_numeric($query['search']) ? 'main.info_id='.(int)$query['search'].' OR ' : ''). implode($op, $search) .')';