public function render() { // if error_reporting = 0 (hide all errors in production) don't show the error if (error_reporting() === 0) { return null; } $data = array('id' => 'sql' . mt_rand(0, 9999), 'error_message' => $this->getErrorMessage(), 'known_error_message' => $this->knownErrorMessage(), 'sql' => $this->statement->getSql(), 'binds' => $this->statement->toStringBindVariables()); $view = $this->createErrorView($data); return $view->render(); }
/** * test that sql is sanitized on construct */ public function testSetSql() { $sql = "select *" . "\r\n\r\n" . "from" . "\r\n\r\n" . "user_tables"; $statement = new Statement($sql, $this->connection); $sql = $statement->getSql(); // \r\n should be replaced with \n everywhere $this->assertNotContains("\r\n", $sql); // remove empty lines $this->assertEquals("select *\nfrom\nuser_tables", $sql); }
/** * Check if the bind variable exists in the sql * With this check, we can use the binds for all reports without the need to define * which bind variables to use for which reports * * @param string $bind * @return boolean */ protected function bindVariableUsedInSql($bind) { $sql = $this->statement->getSql(); if (strpos($sql, $bind) === false) { return false; } // strip the ':' which is a word boundary character $checkBind = ltrim($bind, ':'); // make sure the bind variable is not part of another bind variable (e.g. :reseller vs. :resellersoort) $pattern = '/:\\b' . $checkBind . '\\b/i'; return preg_match($pattern, $sql) === 1; }
/** * @param number $startTime microtime */ protected function log($startTime) { if (!empty($this->logger)) { $this->logger->log($startTime, $this->statement->getSql(), $this->statement->toStringBindVariables()); } }
/** * @return string */ public function render() { $data = array('sql' => $this->statement->getSql(), 'binds' => $this->statement->toStringBindVariables(), 'schema' => $this->statement->getSchema()); $view = new SimpleView(__DIR__ . '/debug.phtml', $data); return $view->render(); }