Exemple #1
0
 def quote_name(self, name):
     # Spanner says "column name not valid" if spaces or hyphens are present
     # (although according the docs, any character should be allowed in
     # quoted identifiers). Replace problematic characters when running the
     # Django tests to prevent crashes. (Don't modify names in normal
     # operation to prevent the possibility of colliding with another
     # column.) https://github.com/orijtech/spanner-orm/issues/204
     if os.environ.get("RUNNING_SPANNER_BACKEND_TESTS") == "1":
         name = name.replace(" ", "_").replace("-", "_")
     return escape_name(name)
Exemple #2
0
    def test_escape_name(self):
        cases = [
            ("SELECT", "`SELECT`"),
            ("id", "id"),
            ("", ""),
            ("dashed-value", "`dashed-value`"),
            ("with space", "`with space`"),
        ]

        for name, want in cases:
            with self.subTest(name=name):
                got = escape_name(name)
                self.assertEqual(got, want)
Exemple #3
0
    def test_escape_name(self):
        from google.cloud.spanner_dbapi.parse_utils import escape_name

        cases = (
            ("SELECT", "`SELECT`"),
            ("dashed-value", "`dashed-value`"),
            ("with space", "`with space`"),
            ("name", "name"),
            ("", ""),
        )
        for name, want in cases:
            with self.subTest(name=name):
                got = escape_name(name)
                self.assertEqual(got, want)
    def quote_name(self, name):
        """
        Return a quoted version of the given table or column name. Also,
        applies backticks to the name that either contain '-' or ' ', or is a
        Cloud Spanner's reserved keyword.

        Spanner says "column name not valid" if spaces or hyphens are present
        (although according to the documantation, any character should be
        allowed in quoted identifiers). Replace problematic characters when
        running the Django tests to prevent crashes. (Don't modify names in
        normal operation to prevent the possibility of colliding with another
        column.)

        See: https://github.com/googleapis/python-spanner-django/issues/204

        :type name: str
        :param name: The Quota name.

        :rtype: :class:`str`
        :returns: Name escaped if it has to be escaped.
        """
        if os.environ.get("RUNNING_SPANNER_BACKEND_TESTS") == "1":
            name = name.replace(" ", "_").replace("-", "_")
        return escape_name(name)