本文整理匯總了Python中flaskext.sqlalchemy.SQLAlchemy.execute方法的典型用法代碼示例。如果您正苦於以下問題:Python SQLAlchemy.execute方法的具體用法?Python SQLAlchemy.execute怎麽用?Python SQLAlchemy.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flaskext.sqlalchemy.SQLAlchemy
的用法示例。
在下文中一共展示了SQLAlchemy.execute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sql_select
# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import execute [as 別名]
def sql_select():
return ''
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 = simplejson.loads(params)
engine = SQLAlchemy().get_engine(current_app)
result = engine.execute(statement, params)
return g.debug_toolbar.render('panels/sqlalchemy_select.html', {
'result': result.fetchall(),
'headers': result.keys(),
'sql': format_sql(statement, params),
'duration': float(request.args['duration']),
})
示例2: sql_explain
# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import execute [as 別名]
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)
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']),
})