diff --git a/core/oql/oqlexception.class.inc.php b/core/oql/oqlexception.class.inc.php index 9f3296294..dc913f86b 100644 --- a/core/oql/oqlexception.class.inc.php +++ b/core/oql/oqlexception.class.inc.php @@ -50,7 +50,7 @@ class OQLException extends CoreException parent::__construct($sMessage, 0); } - public function getHtmlDesc($sHighlightHtmlBegin = '', $sHighlightHtmlEnd = '') + public function getHtmlDesc($sHighlightHtmlBegin = '', $sHighlightHtmlEnd = '') { $sRet = htmlentities($this->m_MyIssue.", found '".$this->m_sUnexpected."' in: ", ENT_QUOTES, 'UTF-8'); $sRet .= htmlentities(substr($this->m_sInput, 0, $this->m_iCol), ENT_QUOTES, 'UTF-8'); @@ -71,7 +71,27 @@ class OQLException extends CoreException return $sRet; } - static protected function FindClosestString($sInput, $aDictionary) + public function GetIssue() + { + return $this->m_MyIssue; + } + + public function GetSuggestions() + { + return $this->m_aExpecting; + } + + public function GetWrongWord() + { + return $this->m_sUnexpected; + } + + public function GetColumn() + { + return $this->m_iCol; + } + + static public function FindClosestString($sInput, $aDictionary) { // no shortest distance found, yet $fShortest = -1; @@ -88,7 +108,7 @@ class OQLException extends CoreException return $sSuggestion; } - if ($fShortest < 0 || ($fDist < 4 && $fDist <= $fShortest)) + if (($fDist <= 3) && ($fShortest < 0 || $fDist <= $fShortest)) { // set the closest match, and shortest distance $sRet = $sSuggestion; diff --git a/pages/run_query.php b/pages/run_query.php index a256cd39a..d43eb51e6 100644 --- a/pages/run_query.php +++ b/pages/run_query.php @@ -122,10 +122,19 @@ try $oFilter = null; $aArgs = array(); + $sSyntaxError = null; if (!empty($sExpression)) { - $oFilter = DBObjectSearch::FromOQL($sExpression); + try + { + $oFilter = DBObjectSearch::FromOQL($sExpression); + } + catch(OqlException $e) + { + $sSyntaxError = $e->getHtmlDesc(); + } + if ($oFilter) { $aArgs = array(); @@ -143,6 +152,10 @@ try } $oFilter->SetInternalParams($aArgs); } + elseif ($sSyntaxError) + { + // Query arguments taken from the page args + } } $oP->add("
\n"); @@ -177,10 +190,34 @@ try $oP->p(Dict::S('UI:RunQuery:SerializedFilter').$oFilter->serialize()); $oP->EndCollapsibleSection(); } -} -catch(CoreException $e) -{ - $oP->p(''.Dict::Format('UI:RunQuery:Error', $e->getHtmlDesc()).''); + elseif ($sSyntaxError) + { + $sWrongWord = $e->GetWrongWord(); + $aSuggestedWords = $e->GetSuggestions(); + if (count($aSuggestedWords) > 0) + { + $sSuggestedWord = OqlException::FindClosestString($sWrongWord, $aSuggestedWords); + + if (strlen($sSuggestedWord) > 0) + { + $oP->p(''.Dict::Format('UI:RunQuery:Error', $e->GetIssue().' '.$sWrongWord).''); + $sBefore = substr($sExpression, 0, $e->GetColumn()); + $sAfter = substr($sExpression, $e->GetColumn() + strlen($sWrongWord)); + $sFixedExpression = $sBefore.$sSuggestedWord.$sAfter; + $sFixedExpressionHtml = $sBefore.''.$sSuggestedWord.''.$sAfter; + $oP->p("Suggesting: $sFixedExpressionHtml"); + $oP->add(''); + } + else + { + $oP->p(''.Dict::Format('UI:RunQuery:Error', $e->getHtmlDesc()).''); + } + } + else + { + $oP->p(''.Dict::Format('UI:RunQuery:Error', $e->getHtmlDesc()).''); + } + } } catch(Exception $e) {