A statement for SQL execution. Args: connection (mysqlx.connection.Connection): Connection object. sql (string): The sql statement to be executed.
| 598 | |
| 599 | |
| 600 | class SqlStatement(Statement): |
| 601 | """A statement for SQL execution. |
| 602 | |
| 603 | Args: |
| 604 | connection (mysqlx.connection.Connection): Connection object. |
| 605 | sql (string): The sql statement to be executed. |
| 606 | """ |
| 607 | |
| 608 | def __init__(self, connection: ConnectionType, sql: str) -> None: |
| 609 | super().__init__(target=None, doc_based=False) |
| 610 | self._connection: ConnectionType = connection |
| 611 | self._sql: str = sql |
| 612 | self._binding_map: Optional[Dict[str, Any]] = None |
| 613 | self._bindings: Union[List, Tuple] = [] |
| 614 | self.has_bindings: bool = False |
| 615 | self.has_limit: bool = False |
| 616 | |
| 617 | @property |
| 618 | def sql(self) -> str: |
| 619 | """string: The SQL text statement.""" |
| 620 | return self._sql |
| 621 | |
| 622 | def get_binding_map(self) -> Dict[str, Any]: |
| 623 | """Returns the binding map dictionary. |
| 624 | |
| 625 | Returns: |
| 626 | dict: The binding map dictionary. |
| 627 | """ |
| 628 | return self._binding_map |
| 629 | |
| 630 | def get_bindings(self) -> Union[Tuple, List]: |
| 631 | """Returns the bindings list. |
| 632 | |
| 633 | Returns: |
| 634 | `list`: The bindings list. |
| 635 | """ |
| 636 | return self._bindings |
| 637 | |
| 638 | def bind(self, *args: Any) -> SqlStatement: |
| 639 | """Binds value(s) to a specific placeholder(s). |
| 640 | |
| 641 | Args: |
| 642 | *args: The value(s) to bind. |
| 643 | |
| 644 | Returns: |
| 645 | mysqlx.SqlStatement: SqlStatement object. |
| 646 | """ |
| 647 | if len(args) == 0: |
| 648 | raise ProgrammingError("Invalid number of arguments to bind") |
| 649 | self.has_bindings = True |
| 650 | bindings = flexible_params(*args) |
| 651 | if isinstance(bindings, (list, tuple)): |
| 652 | self._bindings = bindings |
| 653 | else: |
| 654 | self._bindings.append(bindings) |
| 655 | return self |
| 656 | |
| 657 | def execute(self) -> SqlResult: |