On 5/12/2012, at 4:30 AM, Michael Bayer wrote: > > On Dec 3, 2012, at 10:20 PM, Derek Harland wrote: > >> The MSSQL dialect in 0.8.x seems to have had many of the reflection methods >> changed from something like: >> >> @reflection.cache >> def get_view_names(self, connection, schema=None, **kw): >> >> to >> >> @reflection.cache >> @_db_plus_owner_listing >> def get_view_names(self, connection, dbname, owner, schema, **kw): >> >> where the decorator _db_plus_owner_listing is defined as: >> >> def _db_plus_owner_listing(fn): >> def wrap(dialect, connection, schema=None, **kw): >> dbname, owner = _owner_plus_db(dialect, schema) >> return _switch_db(dbname, connection, fn, dialect, connection, >> dbname, owner, schema, **kw) >> return update_wrapper(wrap, fn) >> >> It seems that they are being extended so people can use schema in this >> fashion: "<database>.<schema>" >> >> This won't work as it stands. Schemas are themselves allowed to contain a >> ".", thus running any reflection on a schema "firstname.lastname" crashes >> (it will try to switch to a database called "firstname" and inspect the >> schema "lastname") > > my understanding is that users are able to use this <dbname>.<schema>.<table> > syntax directly in SQL server, is that correct?
Yes > In that case, how does SQL server make the distinction? If things have an embedded "." then SQL server would ideally make the distinction based on you quoting the database/schema names. This could be done in the Transact-SQL manner: [database].[example.schema.with.dots].[table] or via ANSI sql quoting. "database"."example.schema.with.dots"."table" The MSSQL dialect currently quotes identifiers using the T-SQL standard > If the DB has: > > database A -> schema B -> table C > database DEFAULT -> schema A.B -> table C > > then what does SQL server consider "A.B.C" to mean ? By default, unless any identifier is quoted then A.B.C will be read to mean database.schema.table. ie database A -> schema B -> table C. To path to the latter you'd need to use [A.B].C or "A.B".C. Personally, if I call get_view_names(..., schema="A.B") ... I'd expect it to be looking in schema A.B in the current database. If I wanted to look in another database I'd expect to be calling something like get_view_names(..., schema="B", dbname="A") probably. derek. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
