MCPcopy
hub / github.com/django/django / field_as_sql

Method field_as_sql

django/db/models/sql/compiler.py:1686–1717  ·  view source on GitHub ↗

Take a field and a value intended to be saved on that field, and return placeholder SQL and accompanying params. Check for raw values, fields with get_placeholder_sql(), and compilable defined in that order. When field is None, consider the value raw and use

(self, field, get_placeholder_sql, val)

Source from the content-addressed store, hash-verified

1684 returning_params = ()
1685
1686 def field_as_sql(self, field, get_placeholder_sql, val):
1687 """
1688 Take a field and a value intended to be saved on that field, and
1689 return placeholder SQL and accompanying params. Check for raw values,
1690 fields with get_placeholder_sql(), and compilable defined in that
1691 order.
1692
1693 When field is None, consider the value raw and use it as the
1694 placeholder, with no corresponding parameters returned.
1695 """
1696 if field is None:
1697 # A field value of None means the value is raw.
1698 sql, params = val, []
1699 elif get_placeholder_sql is not None:
1700 # Some fields (e.g. geo fields) need special munging before
1701 # they can be inserted.
1702 sql, params = get_placeholder_sql(val, self, self.connection)
1703 elif hasattr(val, "as_sql"):
1704 # This is an expression, let's compile it.
1705 sql, params = self.compile(val)
1706 else:
1707 # Return the common case for the placeholder
1708 sql, params = "%s", [val]
1709
1710 # The following hook is only used by Oracle Spatial, which sometimes
1711 # needs to yield 'NULL' and () as its placeholder and params instead
1712 # of '%s' and (None,). The 'NULL' placeholder is produced earlier by
1713 # OracleOperations.get_geom_placeholder(). The following line removes
1714 # the corresponding None parameter. See ticket #10888.
1715 params = self.connection.ops.modify_insert_params(sql, params)
1716
1717 return sql, params
1718
1719 def prepare_value(self, field, value):
1720 """

Callers 1

assemble_as_sqlMethod · 0.95

Calls 2

compileMethod · 0.45
modify_insert_paramsMethod · 0.45

Tested by

no test coverage detected