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');
    }
 /**
  * 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
  * @throws DatabaseException
  */
 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 DatabaseException($msg, 0, null, $sql, $parameters);
     } else {
         user_error($msg, $errorLevel);
     }
 }