Example #1
0
 /**
  * void query(Query $query, bool $goOut = true)
  *
  * Displays the query error page
  *
  * @param Query $query Query object containing query error parameters.
  * @param bool $goOut if true, execute an exit()
  * @return void
  * @access public
  */
 public static function query($query, $goOut = true)
 {
     self::message($query->getError() . " " . $query->getDbErrno() . " - " . $query->getDbError() . "." . $query->getSQL());
     if (defined("OPEN_DEBUG") && OPEN_DEBUG) {
         echo PHP_EOL . "<!-- _dbErrno = " . $query->getDbErrno() . "-->" . PHP_EOL;
         echo "<!-- _dbError = " . $query->getDbError() . "-->" . PHP_EOL;
         if ($query->getSQL() != "") {
             echo "<!-- _SQL = " . $query->getSQL() . "-->" . PHP_EOL;
         }
     }
     if ($query->getDbErrno() == 1049) {
         echo '<p><a href="../install.html">' . "Install instructions" . '</a></p>' . PHP_EOL;
     }
     if ($goOut) {
         exit($query->getError());
     }
 }
Example #2
0
/**
 * bool parseSql(string $text)
 *
 * Parses a SQL text
 *
 * @param string $text sentences to parse
 * @return bool false if an error occurs
 * @access public
 * @since 0.8
 */
function parseSql($text)
{
    $controlledErrors = array(1060, 1091);
    $installQ = new Query();
    $installQ->captureError(true);
    /**
     * reading through SQL text executing SQL only when ";" is encountered and if is out of brackets
     */
    $count = strlen($text);
    $sqlSentence = "";
    $outBracket = true;
    for ($i = 0; $i < $count; $i++) {
        $char = $text[$i];
        if ($char == "(") {
            $outBracket = false;
        }
        if ($char == ")") {
            $outBracket = true;
        }
        if ($char == ";" && $outBracket) {
            $result = $installQ->exec($sqlSentence);
            if ($installQ->isError() && !in_array($installQ->getDbErrno(), $controlledErrors)) {
                echo HTML::para(sprintf(_("Process sql [%s]"), $sqlSentence));
                $installQ->close();
                Error::query($installQ, false);
                echo Msg::error(sprintf(_("Error: %s"), $installQ->getDbError()));
                return false;
            }
            $sqlSentence = "";
        } else {
            $sqlSentence .= $char;
        }
    }
    $installQ->close();
    return true;
}