本文整理汇总了Python中explorer.models.Query类的典型用法代码示例。如果您正苦于以下问题:Python Query类的具体用法?Python Query怎么用?Python Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Query类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, request):
sql = request.POST.get("sql", None)
if not sql:
return PlayQueryView.render(request)
query = Query(sql=sql, title="Playground")
query.log(request.user)
return self.render_with_sql(request, query)
示例2: post
def post(self, request):
sql = request.POST.get('sql', None)
if not sql:
return PlayQueryView.render(request)
query = Query(sql=sql, title="Playground")
query.params = url_get_params(request)
return self.render_with_sql(request, query)
示例3: post
def post(self, request, *args, **kwargs):
sql = request.POST.get('sql')
connection = request.POST.get('connection')
query = Query(sql=sql, connection=connection, title='')
ql = query.log(request.user)
query.title = 'Playground - %s' % ql.id
return _export(request, query)
示例4: post
def post(self, request):
sql = request.POST.get('sql')
database = request.POST.get('database')
show_results = request.POST.get('show', True)
query = Query(sql=sql, title="Playground", database=database)
query.log(request.user)
return self.render_with_sql(request, query, show_results)
示例5: csv_from_sql
def csv_from_sql(request):
sql = request.POST.get('sql', None)
if not sql:
return PlayQueryView.render(request)
query = Query(sql=sql)
query.params = url_get_params(request)
fn = generate_report_action()
return fn(None, None, [query, ])
示例6: post
def post(self, request):
sql = request.POST.get('sql')
show_results = request.POST.get('show', True)
query = Query(sql=sql, title="Playground")
passes_blacklist, failing_words = query.passes_blacklist()
error = MSG_FAILED_BLACKLIST % ', '.join(failing_words) if not passes_blacklist else None
run_query = not bool(error) if show_results else False
return self.render_with_sql(request, query, run_query=run_query, error=error)
示例7: validate
def validate(self, value):
query = Query(sql=value)
if not query.available_params():
error = query.error_messages()
if error:
raise ValidationError(
_(error),
params={'value': value},
code="InvalidSql"
)
示例8: validate
def validate(self, value):
"""
Ensure that the SQL passes the blacklist.
:param value: The SQL for this Query model.
"""
query = Query(sql=value)
passes_blacklist, failing_words = query.passes_blacklist()
error = MSG_FAILED_BLACKLIST % ', '.join(failing_words) if not passes_blacklist else None
if error:
raise ValidationError(
error,
code="InvalidSql"
)
示例9: validate
def validate(self, value):
"""
Ensure that the SQL passes the blacklist and executes. Execution check is skipped if params are present.
:param value: The SQL for this Query model.
"""
query = Query(sql=value)
error = MSG_FAILED_BLACKLIST if not query.passes_blacklist() else None
if not error and not query.available_params():
error = query.try_execute()
if error:
raise ValidationError(
_(error),
code="InvalidSql"
)
示例10: validate
def validate(self, value):
"""
Ensure that the SQL passes the blacklist and executes. Execution check is skipped if params are present.
:param value: The SQL for this Query model.
"""
query = Query(sql=value)
passes_blacklist, failing_words = query.passes_blacklist()
error = MSG_FAILED_BLACKLIST % ', '.join(failing_words) if not passes_blacklist else None
if not error and not query.available_params():
try:
query.execute_query_only()
except DatabaseError as e:
error = str(e)
if error:
raise ValidationError(
_(error),
code="InvalidSql"
)
示例11: post
def post(self, request):
sql = request.POST.get('sql')
query = Query(sql=sql, title="Playground")
query.log(request.user)
return self.render_with_sql(request, query)
示例12: download_from_sql
def download_from_sql(request):
sql = request.POST.get('sql')
query = Query(sql=sql, title='')
ql = query.log(request.user)
query.title = 'Playground - %s' % ql.id
return _export(request, query)
示例13: test_playground_query_log
def test_playground_query_log(self):
query = Query(sql='select 1;', title="Playground")
query.log(None)
log = QueryLog.objects.first()
self.assertTrue(log.is_playground)
示例14: handle
def handle(self, **options):
if "explorer" in settings.INSTALLED_APPS:
from explorer.models import Query
queries = (
(
"All Interactive Users",
"""SELECT u.first_name, u.last_name, u.email, u.username, u.is_staff, u.is_superuser,
p.salutation, p.company, p.position_title, p.phone, p.address, p.address2,
p.member_number, p.city, p.state, p.zipcode, p.country, p.url, p.sex,
p.address_type, p.phone2, p.fax, p.work_phone, p.home_phone, p.mobile_phone,
p.notes, p.admin_notes
FROM auth_user u INNER JOIN profiles_profile p
ON u.id=p.user_id
WHERE u.is_active=True
AND p.status=True
AND p.status_detail='active'""",
),
(
"All Members",
"""SELECT u.first_name, u.last_name, u.email, u.username, u.is_staff, u.is_superuser,
p.salutation, p.company, p.position_title, p.phone, p.address, p.address2,
p.member_number, p.city, p.state, p.zipcode, p.country, p.url, p.sex,
p.address_type, p.phone2, p.fax, p.work_phone, p.home_phone, p.mobile_phone,
m.membership_type_id, m.renewal, m.certifications, m.work_experience,
m.referer_url, m.referral_source, m.join_dt, m.expire_dt, m.renew_dt,
m.primary_practice, m.how_long_in_practice, m.application_approved,
m.application_approved_dt, m.areas_of_expertise, m.home_state,
m.year_left_native_country, m.network_sectors, m.networking,
m.government_worker, m.government_agency, m.license_number,
m.license_state, m.status_detail
FROM auth_user u
INNER JOIN profiles_profile p
ON u.id=p.user_id
INNER JOIN memberships_membershipdefault m
ON m.user_id=u.id
WHERE u.is_active=True
AND p.status=True
AND m.status_detail <> 'archive'""",
),
(
"All Corporate Members",
"""SELECT cp.name, cp.address, cp.address2, cp.city, cp.state, cp.zip, cp.country,
cp.phone, cp.email, cp.url, cp.number_employees, cp.chapter, cp.tax_exempt,
cp.annual_revenue, cp.annual_ad_expenditure, cp.description, cp.expectations,
cp.notes, cp.referral_source, cp.ud1, cp.ud2, cp.ud3, cp.ud4, cp.ud5, cp.ud6,
cp.ud7, cp.ud8, cm.corporate_membership_type_id, cm.renewal, cm.renew_dt,
cm.join_dt, cm.expiration_dt, cm.approved, cm.admin_notes, cm.status_detail
FROM corporate_memberships_corpprofile cp
INNER JOIN corporate_memberships_corpmembership cm
ON cp.id=cm.corp_profile_id
WHERE cm.status_detail <> 'archive'""",
),
(
"All Users in a Specific Group (replace <YOUR GROUP ID> with your group id)",
"""SELECT ug.name, u.first_name, u.last_name, u.email, u.username, u.is_staff,
u.is_superuser, p.salutation, p.company, p.position_title, p.phone,
p.address, p.address2, p.member_number, p.city, p.state, p.zipcode,
p.country, p.url, p.sex, p.address_type, p.phone2, p.fax, p.work_phone,
p.home_phone, p.mobile_phone
FROM auth_user u INNER JOIN profiles_profile p
ON u.id=p.user_id INNER JOIN user_groups_groupmembership ugm
on u.id=ugm.member_id INNER JOIN user_groups_group ug on ug.id=ugm.group_id
WHERE ug.id=<YOUR GROUP ID>
AND ugm.status=True
AND ugm.status_detail='active'""",
),
)
for title, sql in queries:
query = Query(title=title, sql=sql)
query.save()
print "Inserted: ", title
else:
print "NO default sqls loaded for SQL Explorer because django-sqlexplorer is not installed"