MCPcopy
hub / github.com/django/django / Substr

Class Substr

django/db/models/functions/text.py:345–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343
344
345class Substr(Func):
346 function = "SUBSTRING"
347 output_field = CharField()
348
349 def __init__(self, expression, pos, length=None, **extra):
350 """
351 expression: the name of a field, or an expression returning a string
352 pos: an integer > 0, or an expression returning an integer
353 length: an optional number of characters to return
354 """
355 if not hasattr(pos, "resolve_expression"):
356 if pos < 1:
357 raise ValueError("'pos' must be greater than 0")
358 expressions = [expression, pos]
359 if length is not None:
360 expressions.append(length)
361 super().__init__(*expressions, **extra)
362
363 def as_sqlite(self, compiler, connection, **extra_context):
364 return super().as_sql(compiler, connection, function="SUBSTR", **extra_context)
365
366 def as_oracle(self, compiler, connection, **extra_context):
367 return super().as_sql(compiler, connection, function="SUBSTR", **extra_context)
368
369
370class Trim(Transform):

Callers 11

slice_expressionMethod · 0.90
slice_expressionMethod · 0.90
test_basicMethod · 0.90
test_startMethod · 0.90
test_pos_gt_zeroMethod · 0.90
test_expressionsMethod · 0.90
test_functionsMethod · 0.90
get_substrMethod · 0.85
get_substrMethod · 0.85

Calls 1

CharFieldClass · 0.90

Tested by 7

test_basicMethod · 0.72
test_startMethod · 0.72
test_pos_gt_zeroMethod · 0.72
test_expressionsMethod · 0.72
test_functionsMethod · 0.72