Skip to content
Snippets Groups Projects
Commit 405053cc authored by Carsten  Rose's avatar Carsten Rose
Browse files

Add two SQL errors to be underlined in exceptions.

parent 3e5f7825
No related branches found
No related tags found
No related merge requests found
Pipeline #1422 passed
......@@ -136,24 +136,13 @@ class AbstractException extends \Exception {
$arrMerged = OnArray::htmlentitiesOnArray(array_merge($arrMsg, $arrDebugShow));
if (!empty($os = $arrMerged[ERROR_MESSAGE_OS] ?? '')) {
// $arrMerged[EXCEPTION_SQL_FINAL] = self::sqlHighlightError($os);
$beforeMatch = htmlentities("the right syntax to use near '", ENT_QUOTES);
$afterMatch = htmlentities("' at line [0-9]*$", ENT_QUOTES);
if (preg_match("/mysqli: 1064.*$beforeMatch.*$afterMatch/", $os)) {
$match = explode("$beforeMatch", $os, 2)[1];
$match = preg_split("/$afterMatch/", $match)[0];
if(!empty($match )) {
$splitSql = explode($match, $arrMerged[EXCEPTION_SQL_FINAL]);
$match = Support::wrapTag('<span class="qfq-wavy-underline">', $match);
$highlightedSql = implode($match, $splitSql);
$arrMerged[EXCEPTION_SQL_FINAL] = $highlightedSql;
}
}
// [ mysqli: 1146 ] Table 'crose_qfq_db.ksajfdkhaskf' doesn't exist
$before=$this->getTableToken( html_entity_decode($arrMerged[ERROR_MESSAGE_OS],ENT_QUOTES));
$arrMerged[EXCEPTION_SQL_FINAL] = $this->sqlHighlightError($arrMerged[ERROR_MESSAGE_OS], 'mysqli: 1146', $arrMerged[EXCEPTION_SQL_FINAL], $before, "' doesn't exist");
$arrMerged[EXCEPTION_SQL_FINAL] = $this->sqlHighlightError($arrMerged[ERROR_MESSAGE_OS], 'mysqli: 1064', $arrMerged[EXCEPTION_SQL_FINAL], "the right syntax to use near '", "' at line [0-9]*$");
$arrMerged[EXCEPTION_SQL_FINAL] = $this->sqlHighlightError($arrMerged[ERROR_MESSAGE_OS], 'mysqli: 1054', $arrMerged[EXCEPTION_SQL_FINAL], "Unknown column '", "' in 'field list'");
}
$htmlDebug = OnArray::arrayToHtmlTable(
array_merge($arrForm, $arrMerged),
'Debug', EXCEPTION_TABLE_CLASS);
......@@ -180,6 +169,45 @@ class AbstractException extends \Exception {
$arrShow = OnArray::htmlentitiesOnArray($arrShow);
return $this->formatMessageUser($arrShow) . $htmlDebug;
}
/**
* @param $os
* @return string
*/
private function getTableToken($os) {
$subject = "Table '.*' ";
$arr = preg_match("/$subject/", $os, $matches);
$arr= explode('.', $matches[0]??'');
return ($arr[0]??'') . '.';
}
/**
* @param $os
* @param $code
* @param $sql
* @param $before
* @param $after
* @return string
*/
private function sqlHighlightError($os, $code, $sql, $before, $after) {
$beforeMatch = htmlentities($before, ENT_QUOTES);
$afterMatch = htmlentities($after, ENT_QUOTES);
if (preg_match("/$code.*$beforeMatch.*$afterMatch/", $os)) {
$arr = explode("$beforeMatch", $os, 2);
$match = $arr[1] ?? '';
$match = preg_split("/$afterMatch/", $match)[0];
if (!empty($match)) {
$splitSql = explode($match, $sql);
$match = Support::wrapTag('<span class="qfq-wavy-underline">', $match);
$highlightedSql = implode($match, $splitSql);
$sql = $highlightedSql;
}
}
return $sql;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment