mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 10:08:45 +02:00
Fixed regression in the tool to test queries: losing the query when there is a syntax error
+ Improved the reporting in case of OQL syntax error, and if the fix is straightforward SVN:trunk[1789]
This commit is contained in:
@@ -50,7 +50,7 @@ class OQLException extends CoreException
|
||||
parent::__construct($sMessage, 0);
|
||||
}
|
||||
|
||||
public function getHtmlDesc($sHighlightHtmlBegin = '<b>', $sHighlightHtmlEnd = '</b>')
|
||||
public function getHtmlDesc($sHighlightHtmlBegin = '<span style="font-weight: bolder">', $sHighlightHtmlEnd = '</span>')
|
||||
{
|
||||
$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;
|
||||
|
||||
@@ -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("<form method=\"get\">\n");
|
||||
@@ -177,10 +190,34 @@ try
|
||||
$oP->p(Dict::S('UI:RunQuery:SerializedFilter').$oFilter->serialize());
|
||||
$oP->EndCollapsibleSection();
|
||||
}
|
||||
}
|
||||
catch(CoreException $e)
|
||||
{
|
||||
$oP->p('<b>'.Dict::Format('UI:RunQuery:Error', $e->getHtmlDesc()).'</b>');
|
||||
elseif ($sSyntaxError)
|
||||
{
|
||||
$sWrongWord = $e->GetWrongWord();
|
||||
$aSuggestedWords = $e->GetSuggestions();
|
||||
if (count($aSuggestedWords) > 0)
|
||||
{
|
||||
$sSuggestedWord = OqlException::FindClosestString($sWrongWord, $aSuggestedWords);
|
||||
|
||||
if (strlen($sSuggestedWord) > 0)
|
||||
{
|
||||
$oP->p('<b>'.Dict::Format('UI:RunQuery:Error', $e->GetIssue().' <em>'.$sWrongWord).'</em></b>');
|
||||
$sBefore = substr($sExpression, 0, $e->GetColumn());
|
||||
$sAfter = substr($sExpression, $e->GetColumn() + strlen($sWrongWord));
|
||||
$sFixedExpression = $sBefore.$sSuggestedWord.$sAfter;
|
||||
$sFixedExpressionHtml = $sBefore.'<span style="background-color:yellow">'.$sSuggestedWord.'</span>'.$sAfter;
|
||||
$oP->p("Suggesting: $sFixedExpressionHtml");
|
||||
$oP->add('<button onClick="$(\'textarea[name=expression]\').val(\''.addslashes($sFixedExpression).'\');">Use this query</button>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP->p('<b>'.Dict::Format('UI:RunQuery:Error', $e->getHtmlDesc()).'</b>');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP->p('<b>'.Dict::Format('UI:RunQuery:Error', $e->getHtmlDesc()).'</b>');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user