MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / TextClause

Class TextClause

lib/sqlalchemy/sql/elements.py:2543–2734  ·  view source on GitHub ↗

Represent a literal SQL text fragment. E.g.:: from sqlalchemy import text t = text("SELECT * FROM users") result = connection.execute(t) The :class:`_expression.TextClause` construct is produced using the :func:`_expression.text` function; see that functio

Source from the content-addressed store, hash-verified

2541
2542
2543class TextClause(AbstractTextClause, inspection.Inspectable["TextClause"]):
2544 """Represent a literal SQL text fragment.
2545
2546 E.g.::
2547
2548 from sqlalchemy import text
2549
2550 t = text("SELECT * FROM users")
2551 result = connection.execute(t)
2552
2553 The :class:`_expression.TextClause` construct is produced using the
2554 :func:`_expression.text`
2555 function; see that function for full documentation.
2556
2557 .. seealso::
2558
2559 :func:`_expression.text`
2560
2561 """
2562
2563 __visit_name__ = "textclause"
2564
2565 _traverse_internals: _TraverseInternalsType = [
2566 ("_bindparams", InternalTraversal.dp_string_clauseelement_dict),
2567 ("text", InternalTraversal.dp_string),
2568 ] + ExecutableStatement._executable_traverse_internals
2569
2570 _bind_params_regex = re.compile(r"(?<![:\w\x5c]):(\w+)(?!:)", re.UNICODE)
2571
2572 @property
2573 def _is_star(self) -> bool: # type: ignore[override]
2574 return self.text == "*"
2575
2576 def __init__(self, text: str):
2577 self._bindparams: Dict[str, BindParameter[Any]] = {}
2578
2579 def repl(m):
2580 self._bindparams[m.group(1)] = BindParameter(m.group(1))
2581 return ":%s" % m.group(1)
2582
2583 # scan the string and search for bind parameter names, add them
2584 # to the list of bindparams
2585 self.text = self._bind_params_regex.sub(repl, text)
2586
2587 @_generative
2588 def bindparams(
2589 self,
2590 *binds: BindParameter[Any],
2591 **names_to_values: Any,
2592 ) -> Self:
2593 """Establish the values and/or types of bound parameters within
2594 this :class:`_expression.TextClause` construct.
2595
2596 Given a text construct such as::
2597
2598 from sqlalchemy import text
2599
2600 stmt = text(

Callers 3

__init__Method · 0.85
_text_clauseMethod · 0.85
textFunction · 0.85

Calls 1

compileMethod · 0.45

Tested by

no test coverage detected