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:
Romain Quetiez
2012-01-19 10:19:09 +00:00
parent 5767d14c3e
commit 9fce2da012
2 changed files with 65 additions and 8 deletions

View File

@@ -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)
{