Michael Bayer wrote:
> just FTR, the current expected behavior of default schemas is that if
> your tables are known to exist in the default schema configured on the
> database connection, you leave the "schema" attribute on Table blank.
> otherwise, you set it.
The mssql dialect does not ask the server what the default schema is.
It just sets it to 'dbo', so for user scott with default schema TEST
this would yield the wrong value:
import sqlalchemy as sa
e = sa.create_engine('mssql://scott:ti...@blackie/test')
print e.dialect.get_default_schema_name(e) # returns dbo
This would return the value from there server:
def get_default_schema_name(self, connection):
# get the username
query = "SELECT user_name() as user_name;"
rp = connection.execute(sql.text(query))
row = rp.fetchone()
rp.close()
if row is not None:
user_name = row.user_name
# now, get the default schema
query = """
SELECT default_schema_name FROM
sys.database_principals
WHERE name = :user_name
AND type = 'S'
"""
rp = connection.execute(sql.text(query), user_name=user_name)
row = rp.fetchone()
rp.close()
if row is not None:
return row.default_schema_name
return self.schema_name
postgres doesn't even set a schema_name on the Dialect. It goes like this:
def get_default_schema_name(self, connection):
return connection.scalar("select current_schema()", None)
get_default_schema_name = base.connection_memoize(
('dialect', 'default_schema_name'))(get_default_schema_name)
Shouldn't mssql do something similar to Postgres here?
--Randall
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---