Mike Bayer avatar Mike Bayer committed e477899

- more fixes
- bindparams
- document the quote construct

Comments (0)

Files changed (6)

doc/build/core/sqlelement.rst

    :members:
    :special-members:
 
+.. autoclass:: sqlalchemy.sql.elements.quoted_name
+
 .. autoclass:: UnaryExpression
    :members:
 

lib/sqlalchemy/dialects/mysql/base.py

             visit_primary_key_constraint(constraint)
         if "mysql_using" in constraint.kwargs:
             using = constraint.kwargs['mysql_using']
-            text += " USING %s" % (
-                self.preparer.quote(using))
+            text += " USING %s" % (self.preparer.quote(using))
         return text
 
     def visit_drop_index(self, drop):

lib/sqlalchemy/sql/compiler.py

                 tablename = self._truncated_identifier("alias", tablename)
 
             return schema_prefix + \
-                    self.preparer.quote(tablename, table.quote) + \
+                    self.preparer.quote(tablename) + \
                     "." + name
 
     def escape_literal_column(self, text):
         return self.sql_compiler.post_process_text(ddl.statement % context)
 
     def visit_create_schema(self, create):
-        schema = self.preparer.format_schema(create.element, create.quote)
+        schema = self.preparer.format_schema(create.element)
         return "CREATE SCHEMA " + schema
 
     def visit_drop_schema(self, drop):
-        schema = self.preparer.format_schema(drop.element, drop.quote)
+        schema = self.preparer.format_schema(drop.element)
         text = "DROP SCHEMA " + schema
         if drop.cascade:
             text += " CASCADE"
                 or (lc_value != value))
 
     def quote_schema(self, schema, force=None):
-        """Quote a schema.
+        """Conditionally quote a schema.
+
+        Subclasses can override this to provide database-dependent
+        quoting behavior for schema names.
+
+        the 'force' flag should be considered deprecated.
 
-        Subclasses should override this to provide database-dependent
-        quoting behavior.
         """
         return self.quote(schema, force)
 
     def quote(self, ident, force=None):
+        """Conditionally quote an identifier.
+
+        the 'force' flag should be considered deprecated.
+        """
 
         if isinstance(ident, elements.quoted_name):
             force = ident.quote
 
     def format_sequence(self, sequence, use_schema=True):
         name = self.quote(sequence.name)
-        if not self.omit_schema and use_schema and \
-            sequence.schema is not None:
-            name = self.quote_schema(sequence.schema) + \
-                        "." + name
+        if not self.omit_schema and use_schema and sequence.schema is not None:
+            name = self.quote_schema(sequence.schema) + "." + name
         return name
 
     def format_label(self, label, name=None):
         result = self.quote(name)
         if not self.omit_schema and use_schema \
             and getattr(table, "schema", None):
-            result = self.quote_schema(table.schema) + \
-                                "." + result
+            result = self.quote_schema(table.schema) + "." + result
         return result
 
     def format_schema(self, name, quote=None):
             if use_table:
                 return self.format_table(
                             column.table, use_schema=False,
-                            name=table_name) + "." + \
-                            self.quote(name)
+                            name=table_name) + "." + self.quote(name)
             else:
                 return self.quote(name)
         else:

lib/sqlalchemy/sql/elements.py

 
 
 class quoted_name(util.text_type):
-    """A unicode subclass used to identify names
-    that are unconditionally quoted (or not quoted)
+    """Represent a SQL identifier combined with quoting preferences.
+
+    :class:`.quoted_name` is a Python unicode/str subclass which
+    represents a particular identifier name at the same
+    time as a "quote" flag.  This "quote" flag, when set to
+    True or False, overrides all automatic quoting behavior
+    for this identifier in order to either unconditionally quote
+    or to not quote the name.
+
+    A :class:`.quoted_name` object with ``quote=True`` is also
+    prevented from being modified in the case of a so-called
+    "name normalize" option.  Certain database backends, such as
+    Oracle, Firebird, and DB2 "normalize" case-insensitive names
+    as uppercase.  The SQLAlchemy dialects for these backends
+    convert from SQLAlchemy's lower-case-means-insensitive convention
+    to the upper-case-means-insensitive conventions of those backends.
+    The ``quote=True`` flag here will prevent this conversion from occurring
+    to support an identifier that's quoted as all lower case against
+    such a backend.
+
+    The :class:`.quoted_name` object is normally created automatically
+    when specifying the name for key schema constructs such as :class:`.Table`,
+    :class:`.Column`, and others.   The class can also be passed explicitly
+    as the name to any function that receives a name which can be quoted.
+    Such as to use the :meth:`.Engine.has_table` method with an unconditionally
+    quoted name::
+
+        from sqlaclchemy import create_engine
+        from sqlalchemy.sql.elements import quoted_name
+
+        engine = create_engine("oracle+cx_oracle://some_dsn")
+        engine.has_table(quoted_name("some_table", True))
+
+    The above logic will run the "has table" logic against the Oracle backend,
+    passing the name exactly as ``"some_table"`` without converting to
+    upper case.
+
+    .. versionadded:: 0.9.0
 
     """
 

lib/sqlalchemy/sql/schema.py

                     self._columns.remove(c)
 
         for key in ('quote', 'quote_schema'):
-            raise exc.ArgumentError("not supported")
-            #if key in kwargs:
-            #    setattr(self, key, kwargs.pop(key))
+            raise exc.ArgumentError(
+                    "Can't redefine 'quote' or 'quote_schema' arguments")
 
         if 'info' in kwargs:
             self.info = kwargs.pop('info')

lib/sqlalchemy/sql/selectable.py

     __visit_name__ = 'fromclause'
     named_with_column = False
     _hide_froms = []
-    quote = None
     schema = None
     _memoized_property = util.group_expirable_memoized_property(["_columns"])
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.