Conditionally quote an identifier. The identifier is quoted if it is a reserved word, contains quote-necessary characters, or is an instance of :class:`.quoted_name` which includes ``quote`` set to ``True``. Subclasses can override this to provide database-dependent
(self, ident: str, force: Any = None)
| 7797 | return self.quote(schema) |
| 7798 | |
| 7799 | def quote(self, ident: str, force: Any = None) -> str: |
| 7800 | """Conditionally quote an identifier. |
| 7801 | |
| 7802 | The identifier is quoted if it is a reserved word, contains |
| 7803 | quote-necessary characters, or is an instance of |
| 7804 | :class:`.quoted_name` which includes ``quote`` set to ``True``. |
| 7805 | |
| 7806 | Subclasses can override this to provide database-dependent |
| 7807 | quoting behavior for identifier names. |
| 7808 | |
| 7809 | :param ident: string identifier |
| 7810 | :param force: unused |
| 7811 | |
| 7812 | .. deprecated:: 0.9 |
| 7813 | |
| 7814 | The :paramref:`.IdentifierPreparer.quote.force` |
| 7815 | parameter is deprecated and will be removed in a future |
| 7816 | release. This flag has no effect on the behavior of the |
| 7817 | :meth:`.IdentifierPreparer.quote` method; please refer to |
| 7818 | :class:`.quoted_name`. |
| 7819 | |
| 7820 | """ |
| 7821 | if force is not None: |
| 7822 | # not using the util.deprecated_params() decorator in this |
| 7823 | # case because of the additional function call overhead on this |
| 7824 | # very performance-critical spot. |
| 7825 | util.warn_deprecated( |
| 7826 | "The IdentifierPreparer.quote.force parameter is " |
| 7827 | "deprecated and will be removed in a future release. This " |
| 7828 | "flag has no effect on the behavior of the " |
| 7829 | "IdentifierPreparer.quote method; please refer to " |
| 7830 | "quoted_name().", |
| 7831 | # deprecated 0.9. warning from 1.3 |
| 7832 | version="0.9", |
| 7833 | ) |
| 7834 | |
| 7835 | force = getattr(ident, "quote", None) |
| 7836 | |
| 7837 | if force is None: |
| 7838 | if ident in self._strings: |
| 7839 | return self._strings[ident] |
| 7840 | else: |
| 7841 | if self._requires_quotes(ident): |
| 7842 | self._strings[ident] = self.quote_identifier(ident) |
| 7843 | else: |
| 7844 | self._strings[ident] = ident |
| 7845 | return self._strings[ident] |
| 7846 | elif force: |
| 7847 | return self.quote_identifier(ident) |
| 7848 | else: |
| 7849 | return ident |
| 7850 | |
| 7851 | def format_collation(self, collation_name): |
| 7852 | if self.quote_case_sensitive_collations: |