"""
Create SQL statements for QuerySets.
The code in here encapsulates all of the SQL construction so that QuerySets
themselves do not have to (and could be backed by things other than SQL
databases). The abstraction barrier only works one way: this module has to know
all about the internals of models in order to get the information it needs.
"""
import copy
import difflib
import functools
import inspect
import sys
import warnings
from collections import Counter, namedtuple
from collections.abc import Iterator, Mapping
from itertools import chain, count, product
from string import ascii_uppercase
from django.core.exceptions import (
EmptyResultSet, FieldDoesNotExist, FieldError,
)
from django.db import DEFAULT_DB_ALIAS, NotSupportedError, connections
from django.db.models.aggregates import Count
from django.db.models.constants import LOOKUP_SEP
from django.db.models.expressions import (
BaseExpression, Col, F, OuterRef, Ref, SimpleCol,
)
from django.db.models.fields import Field
from django.db.models.fields.related_lookups import MultiColSource
from django.db.models.lookups import Lookup
from django.db.models.query_utils import (
Q, check_rel_lookup_compatibility, refs_expression,
)
from django.db.models.sql.constants import (
INNER, LOUTER, ORDER_DIR, ORDER_PATTERN, SINGLE,
)
from django.db.models.sql.datastructures import (
BaseTable, Empty, Join, MultiJoin,
)
from django.db.models.sql.where import (
AND, OR, ExtraWhere, NothingNode, WhereNode,
)
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.functional import cached_property
from django.utils.tree import Node
__all__ = ['Query', 'RawQuery']
def get_field_names_from_opts(opts):
return set(chain.from_iterable(
(f.name, f.attname) if f.concrete else (f.name,)
for f in opts.get_fields()
))
def get_children_from_q(q):
for child in q.children:
if isinstance(child, Node):
yield from get_children_from_q(child)
else:
yield child
JoinInfo = namedtuple(
'JoinInfo',
('final_field', 'targets', 'opts', 'joins', 'path', 'transform_function')
)
def _get_col(target, field, alias, simple_col):
if simple_col:
return SimpleCol(target, field)
return target.get_col(alias, field)
class RawQuery:
"""A single raw SQL query."""
def __init__(self, sql, using, params=None):
self.params = params or ()
self.sql = sql
self.using = using
self.cursor = None
# Mirror some properties of a normal query so that
# the compiler can be used to process results.
self.low_mark, self.high_mark = 0, None # Used for offset/limit
self.extra_select = {}
self.annotation_select = {}
def chain(self, using):
return self.clone(using)
def clone(self, using):
return RawQuery(self.sql, using, params=self.params)
def get_columns(self):
if self.cursor is None:
self._execute_query()
converter = connections[self.using].introspection.identifier_converter
return [converter(column_meta[0])
for column_meta in self.cursor.description]
def __iter__(self):
# Always execute a new query for a new iterator.
# This could be optimized with a cache at the expense of RAM.
self._execute_query()
if not connections[self.using].features.can_use_chunked_reads:
# If the database can't use chunked reads we need to make sure we
# evaluate the entire query up front.
result = list(self.cursor)
else:
result = self.cursor
return iter(result)
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self)
@property
def params_type(self):
return dict if isinstance(self.params, Mapping) else tuple
def __str__(self):
return self.sql % self.params_type(self.params)
def _execute_query(self):
connection = connections[self.using]
# Adapt parameters to the database, as much as possible considering
# that the target type isn't known. See #17755.
params_type = self.params_type
adapter = connection.ops.adapt_unknown_value
if params_type is tuple:
params = tuple(adapter(val) for val in self.params)
elif params_type is dict:
params = {key: adapter(val) for key, val in self.params.items()}
else:
raise RuntimeError("Unexpected params type: %s" % params_type)
self.cursor = connection.cursor()
self.cursor.execute(self.sql, params)
class Query(BaseExpression):
"""A single SQL query."""
alias_prefix = 'T'
subq_aliases = frozenset([alias_prefix])
compiler = 'SQLCompiler'
def __init__(self, model, where=WhereNode):
self.model = model
self.alias_refcount = {}
# alias_map is the most important data structure regarding joins.
# It's used for recording which joins exist in the query and what
# types they are. The key is the alias of the joined table (possibly
# the table name) and the value is a Join-like object (see
# sql.datastructures.Join for more information).
self.alias_map = {}
# Sometimes the query contains references to aliases in outer queries (as
# a result of split_exclude). Correct alias quoting needs to know these
# aliases too.
# Map external tables to whether they are aliased.
self.external_aliases = {}
self.table_map = {} # Maps table names to list of aliases.
self.default_cols = True
self.default_ordering = True
self.standard_ordering = True
self.used_aliases = set()
self.filter_is_sticky = False
self.subquery = False
# SQL-related attributes
# Select and related select clauses are expressions to use in the
# SELECT clause of the query.
# The select is used for cases where we want to set up the select
# clause to contain other than default fields (values(), subqueries...)
# Note that annotations go to annotations dictionary.
self.select = ()
self.where = where()
self.where_class = where
# The group_by attribute can have one of the following forms:
# - None: no group by at all in the query
# - A tuple of expressions: group by (at least) those expressions.
# String refs are also allowed for now.
# - True: group by all select fields of the model
# See compiler.get_group_by() for details.
self.group_by = None
self.order_by = ()
self.low_mark, self.high_mark = 0, None # Used for offset/limit
self.distinct = False
self.distinct_fields = ()
self.select_for_update = False
self.select_for_update_nowait = False
self.select_for_update_skip_locked = False
self.select_for_update_of = ()
self.select_related = False
# Arbitrary limit for select_related to prevents infinite recursion.
self.max_depth = 5
# Holds the selects defined by a call to values() or values_list()
# excluding annotation_select and extra_select.
self.values_select = ()
# SQL annotation-related attributes
self.annotations = {} # Maps alias -> Annotation Expression
self.annotation_select_mask = None
self._annotation_select_cache = None
# Set combination attributes
self.combinator = None
self.combinator_all = False
self.combined_queries = ()
# These are for extensions. The contents are more or less appended
# verbatim to the appropriate clause.
self.extra = {} # Maps col_alias -> (col_sql, params).
self.extra_select_mask = None
self._extra_select_cache = None
self.extra_tables = ()
self.extr
没有合适的资源?快使用搜索试试~ 我知道了~
python健康饮食后台管理系统
共4574个文件
po:1132个
mo:1132个
py:894个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 72 浏览量
2023-06-15
07:21:50
上传
评论 2
收藏 30.76MB ZIP 举报
温馨提示
python健康饮食后台管理系统
资源推荐
资源详情
资源评论
收起资源包目录
python健康饮食后台管理系统 (4574个子文件)
semantic.css 828KB
index.css 227KB
bootstrap.min.css 96KB
all.min.css 54KB
font-awesome.min.css 30KB
cascader.css 29KB
date-picker.css 28KB
transfer.css 27KB
col.css 25KB
pagination.css 23KB
table.css 22KB
time-picker.css 22KB
message-box.css 21KB
userinfo.css 19KB
select.css 18KB
slider.css 18KB
responsive.css 18KB
responsive.css 17KB
select2.css 17KB
select2.css 17KB
tabs.css 16KB
base.css 16KB
base.css 16KB
base.css 16KB
select2.min.css 15KB
select2.min.css 15KB
dropdown.css 14KB
time-select.css 13KB
table-column.css 13KB
cascader-panel.css 13KB
tree.css 13KB
upload.css 13KB
icon.css 12KB
autocomplete.css 11KB
input-number.css 10KB
widgets.css 10KB
widgets.css 10KB
button.css 10KB
menu.css 9KB
forms.css 8KB
autocomplete.css 8KB
autocomplete.css 8KB
forms.css 8KB
color-picker.css 7KB
comon0.css 7KB
checkbox.css 7KB
input.css 7KB
index.css 6KB
changelists.css 6KB
changelists.css 6KB
drawer.css 5KB
step.css 5KB
collapse.css 5KB
aircraft.css 5KB
bootstrap-theme.css 5KB
tag.css 5KB
orange.css 5KB
purple.css 4KB
x-blue.css 4KB
ant.design.css 4KB
e-purple.css 4KB
e-green.css 4KB
e-red.css 4KB
e-black.css 4KB
x-red.css 4KB
e-purple-pro.css 4KB
x-green.css 4KB
e-green-pro.css 4KB
e-red-pro.css 4KB
e-black-pro.css 4KB
highdmin.css 4KB
admin.lte.css 4KB
layui.css 4KB
gray.css 4KB
dark.green.css 4KB
green.css 4KB
simpleui.css 4KB
element.css 4KB
e-blue.css 4KB
black.css 4KB
light.css 4KB
e-blue-pro.css 4KB
waves.min.css 4KB
rtl.css 4KB
rtl.css 4KB
image.css 3KB
radio.css 3KB
base.css 3KB
form.css 3KB
dialog.css 3KB
select-dropdown.css 3KB
tooltip.css 3KB
carousel.css 2KB
radio-button.css 2KB
progress.css 2KB
popover.css 2KB
link.css 2KB
message.css 2KB
responsive_rtl.css 2KB
alert.css 2KB
共 4574 条
- 1
- 2
- 3
- 4
- 5
- 6
- 46
资源评论
Roc-xb
- 粉丝: 12w+
- 资源: 8207
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功