From 1bb569c84b0180970e80618fe58b956ac1987d39 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sat, 26 Dec 2020 09:27:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EB=84=88=EB=AC=B4=20=EB=A7=8E=EC=9D=80=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95.=20`too=20much=20proble?= =?UTF-8?q?ms`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index e9abf65e2..2d6f94947 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -465,7 +465,7 @@ class VariableBase if (strlen($item) > 2 && substr($item, 0, 1) === '(' && substr($item, -1) === ')') { $parsed_keywords = $this->_parseSearchKeywords($column, substr($item, 1, -1)); - $conditions[] = "(". $parsed_keywords[0] . ")"; + $conditions[] = $parsed_keywords[0]; $conditions[] = 'AND'; $params = array_merge($params, $parsed_keywords[1]); continue; @@ -511,7 +511,7 @@ class VariableBase { $conditions[] = $last_condition; } - $conditions[] = sprintf('%s', $item); + $conditions[] = $item; } else { From 9e847dadcb007127635f65ecc359981672c8a15d Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 19:44:18 +0900 Subject: [PATCH 2/2] code refining! --- .../parsers/dbquery/variablebase.php | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 2d6f94947..c93c91ea5 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -450,11 +450,7 @@ class VariableBase $escaped_hyphen = false; // parse the value (text); - if (strpos ($value, '"') !== false) - { - $escaped_quot = true; - $value = str_replace('"', '"', $value); - } + $value = str_replace('"', '"', $value); $keywords = preg_split('/(\([^\)]*\))|(\-?"[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); $conditions = array(); $operators = array('AND', 'OR', '|'); @@ -462,41 +458,19 @@ class VariableBase foreach ($keywords as $item) { // treat parenthesis - if (strlen($item) > 2 && substr($item, 0, 1) === '(' && substr($item, -1) === ')') + if (substr($item, 0, 1) === '(' && substr($item, -1) === ')') { - $parsed_keywords = $this->_parseSearchKeywords($column, substr($item, 1, -1)); - $conditions[] = $parsed_keywords[0]; - $conditions[] = 'AND'; - $params = array_merge($params, $parsed_keywords[1]); - continue; - } - - // trim quotation mark - if (strlen($item) > 2 && (substr($item, 0, 1) === substr($item, -1)) && substr($item, -1) === '"') - { - $item = substr($item, 1, -1); - if (substr($item, 0, 1) === '-') + $item = trim(substr($item, 1, -1)); + if ( $item !== "" ) { - $escaped_hyphen = true; + $parsed_keywords = $this->_parseSearchKeywords($column, substr($item, 1, -1)); + $conditions[] = $parsed_keywords[0]; + $conditions[] = 'AND'; + $params = array_merge($params, $parsed_keywords[1]); } - } - elseif (strlen($item) > 3 && (substr($item, 0, 1) === '-') && (substr($item, 1, 1) === substr($item, -1)) && substr($item, -1) === '"') - { - $item = '-' . substr($item, 2, -1); - } - - // pass blank text - if (trim($item) === "") - { continue; } - if($escaped_quot === true) - { - $value = str_replace('"', '"', $value); - $escaped_quot = false; - } - // process 'AND' or 'OR' operator if (in_array($item, $operators)) { @@ -505,16 +479,13 @@ class VariableBase $item = 'OR'; } // remove the last point (would be an operator) - $last_condition = array_pop($conditions); - // the last condition might not be an operator. - if (!in_array($last_condition, $operators)) - { - $conditions[] = $last_condition; - } + array_pop($conditions); $conditions[] = $item; } else { + $value = str_replace('"', '"', $value); + if (substr($item, 0, 1) === '-' && $escaped_hyphen !== true) { $conditions[] = sprintf('%s NOT LIKE ?', $column); @@ -524,6 +495,21 @@ class VariableBase { $conditions[] = sprintf('%s LIKE ?', $column); } + + // trim quotation mark + if (substr($item, 0, 6) === substr($item, -6) && substr($item, -6) === '"') + { + $item = substr($item, 6, -6); + + } + + // pass blank text + if (trim($item) === "") + { + array_pop($conditions); + continue; + } + $params[] = '%' . str_replace(['\\', '_', '%'], ['\\\\', '\_', '\%'], $item) . '%'; // if there is no operator, assume 'AND' $conditions[] = 'AND';