コード例 #1
0
    public function testNewlineHanding()
    {
        $formatter = new SQLFormatter();
        $sqlBefore = <<<SQL
SELECT Test.Foo, Test.Bar FROM Test WHERE 'From' = "Where"
SQL;
        $sqlAfter = <<<SQL
SELECT Test.Foo, Test.Bar
FROM Test
WHERE 'From' = "Where"
SQL;
        $this->assertEquals($formatter->formatPlain($sqlBefore), $sqlAfter, 'correct replacement of newlines and don\'t replace non-uppercase tokens');
        $sqlBefore = <<<SQL
SELECT Test.Foo, Test.Bar
FROM Test
WHERE
  'From' = "Where"
SQL;
        $sqlAfter = <<<SQL
SELECT Test.Foo, Test.Bar
FROM Test
WHERE
  'From' = "Where"
SQL;
        $this->assertEquals($formatter->formatPlain($sqlBefore), $sqlAfter, 'Leave existing newlines and indentation in place');
    }
コード例 #2
0
 /**
  * Error handler for database errors.
  * All database errors will call this function to report the error.  It isn't a static function;
  * it will be called on the object itself and as such can be overridden in a subclass.
  * Subclasses should run all errors through this function.
  *
  * @todo hook this into a more well-structured error handling system.
  * @param string $msg The error message.
  * @param integer $errorLevel The level of the error to throw.
  * @param string $sql The SQL related to this query
  * @param array $parameters Parameters passed to the query
  */
 protected function databaseError($msg, $errorLevel = E_USER_ERROR, $sql = null, $parameters = array())
 {
     // Prevent errors when error checking is set at zero level
     if (empty($errorLevel)) {
         return;
     }
     // Format query if given
     if (!empty($sql)) {
         $formatter = new SQLFormatter();
         $formattedSQL = $formatter->formatPlain($sql);
         $msg = "Couldn't run query:\n\n{$formattedSQL}\n\n{$msg}";
     }
     if ($errorLevel === E_USER_ERROR) {
         // Treating errors as exceptions better allows for responding to errors
         // in code, such as credential checking during installation
         throw new SS_DatabaseException($msg, 0, null, $sql, $parameters);
     } else {
         user_error($msg, $errorLevel);
     }
 }
コード例 #3
0
 public function databaseError($msg, $errorLevel = E_USER_ERROR)
 {
     // try to extract and format query
     if (preg_match('/Couldn\'t run query: ([^\\|]*)\\|\\s*(.*)/', $msg, $matches)) {
         $formatter = new SQLFormatter();
         $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
     }
     $connect_errno = $this->dbConn->connect_errno;
     $errno = $this->dbConn->errno;
     $sqlstate = $this->dbConn->sqlstate;
     $error = $this->dbConn->error;
     $connect_error = $msg;
     $msg = sprintf('connect_errno : %s - errno : %s - sqlstate : %s - error : %s - connect_error : %s', $connect_errno, $errno, $sqlstate, $error, $connect_error);
     SS_Log::log($msg, SS_Log::ERR);
     if (Director::get_environment_type() === "live") {
         ob_clean();
         $maintenance_page = file_get_contents(Director::baseFolder() . '/maintenance/index.html');
         echo $maintenance_page;
         header("HTTP/1.0 502 Bad Gateway");
         exit;
     } else {
         user_error($msg);
     }
 }
コード例 #4
0
 function databaseError($msg, $errorLevel = E_USER_ERROR)
 {
     // try to extract and format query
     if (preg_match('/Couldn\'t run query: ([^\\|]*)\\|\\s*(.*)/', $msg, $matches)) {
         $formatter = new SQLFormatter();
         $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
     }
     user_error($msg, $errorLevel);
 }