Exemplo n.º 1
0
 def json(self):
     if __debug__:
         _assertHaveJson()
     if self.mimetype == 'application/json':
         reqCharset = self.mimetype_params.get('charset')
         try:
             if reqCharset is not None:
                 return json.loads(self.data, encoding=reqCharset)
             return json.loads(self.data)
         except ValueError, error:
             return self.jsonLoadFailedHandler(error)
Exemplo n.º 2
0
def sql_explain():
    statement = request.args['sql']
    params = request.args['params']

    # Validate hash
    hash = hashlib.sha1(
        current_app.config['SECRET_KEY'] + statement + params).hexdigest()
    if hash != request.args['hash']:
        return abort(406)

    # Make sure it is a select statement
    if not statement.lower().strip().startswith('select'):
        return abort(406)

    params = json.loads(params)

    # engine = SQLAlchemy().get_engine(current_app)
    from app.models import engine

    if engine.driver == 'pysqlite':
        query = 'EXPLAIN QUERY PLAN %s' % statement
    else:
        query = 'EXPLAIN %s' % statement

    result = engine.execute(query, params)
    return g.debug_toolbar.render('panels/sqlalchemy_explain.html', {
        'result': result.fetchall(),
        'headers': result.keys(),
        'sql': format_sql(statement, params),
        'duration': float(request.args['duration']),
    })