Esempio n. 1
0
def test_format_sql_pygments():
    sql = 'select 1'
    html = format_sql(sql, {})
    assert isinstance(html, Markup)
    assert html.startswith('<div')
    assert 'select' in html
    assert '1' in html
Esempio n. 2
0
def test_format_sql_pygments_non_ascii():
    sql = b"select 'abc \xff xyz'"
    html = format_sql(sql, {})
    assert isinstance(html, Markup)
    assert html.startswith('<div')
    assert 'select' in html
    assert 'abc' in html
    assert 'xyz' in html
Esempio n. 3
0
def sql_select(explain=False):
    statement, params = load_query(request.args['query'])
    engine = SQLAlchemy().get_engine(current_app)

    if explain:
        if engine.driver == 'pysqlite':
            statement = 'EXPLAIN QUERY PLAN\n%s' % statement
        else:
            statement = 'EXPLAIN\n%s' % statement

    result = engine.execute(statement, params)
    return g.toolbar.render('panels/sqlalchemy_select.html', {
        'result': result.fetchall(),
        'headers': result.keys(),
        'sql': format_sql(statement, params),
        'duration': float(request.args['duration']),
    })
Esempio n. 4
0
    def content(self):
        queries = get_queries()

        if not queries and not is_available():
            return self.render('panels/sqlalchemy_error.html', {
                'json_available': json_available,
                'sqlalchemy_available': sqlalchemy_available,
                'extension_used': extension_used(),
                'recording_enabled': recording_enabled(),
            })

        data = []
        for query in queries:
            data.append({
                'duration': query.duration,
                'sql': format_sql(query.statement, query.parameters),
                'signed_query': dump_query(query.statement, query.parameters),
                'context_long': query.context,
                'context': format_fname(query.context)
            })
        return self.render('panels/sqlalchemy.html', {'queries': data})
Esempio n. 5
0
def test_format_sql_no_pygments_escape_html(no_pygments):
    sql = 'select x < 1'
    formatted = format_sql(sql, {})
    assert not isinstance(formatted, Markup)
    assert Markup('%s') % formatted == 'select x &lt; 1'
Esempio n. 6
0
def test_format_sql_no_pygments_non_ascii(no_pygments):
    sql = b"select '\xff'"
    formatted = format_sql(sql, {})
    assert formatted.startswith(u"select '")
Esempio n. 7
0
def test_format_sql_no_pygments(no_pygments):
    sql = 'select 1'
    assert format_sql(sql, {}) == sql