protected function error($sql, \PDOStatement $statement = null)
    {
        $error = $this->pdo->errorInfo();
        if(!$error[1] and $statement) {
            $error = $statement->errorInfo();
            $statement->closeCursor();
            unset($statement);
        }

        $code = is_int($error[0]) ? $error[0] : null;
        return new \PDOException('[' . $error[0] . '] ' . $error[2] . ', in query (' . $sql . ')', $code);
    }