On Wed, Nov 30, 2005 at 10:35:17AM -0800, Tyler MacDonald wrote:
> 
> > This is something I've been meaning to address for a while. I was
> > thinking of something like:
> > 
> >     $schema_name = $dbh->current_schema
> 
>       I really like this. I read your exchange with Steffen Goeldner and
> that prompted me to take a look at the get_info method. I expected either
> SQL_DATABASE_NAME (16) or SQL_CATALOG_NAME (10003) to tell me the current
> database name, but I guess I was wrong; on both MySQL and Pg,
> SQL_DATABASE_NAME returns nothing; under MySQL, SQL_CATALOG_NAME returns
> 'Y', under Pg, 'N'.

See 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqlgetinfo.asp

> > Why not help save the world and help me add current_schema() to the DBI
> > and send implementations to the authors of drivers you're using?
> 
>       SQL_DATABASE_NAME is such a self-explanitory label that I have to
> believe this is the right place to put the information we're after, but I
> could be way off-base.

See above url. The wording isn't very clear:

: A character string with the name of the current database in use, if the
: data source defines a named object called "database".  Note   In ODBC
: 3.x, the value returned for this InfoType can also be returned by
: calling SQLGetConnectAttr with an Attribute argument of 
SQL_ATTR_CURRENT_CATALOG.

but since it's saying that SQL_DATABASE_NAME == SQL_ATTR_CURRENT_CATALOG
and a 'catalog' is usually not the same thing as a 'schema' (catalogs contain
schemas) it's clear that SQL_DATABASE_NAME isn't what you're after.
It may work for some databases and drivers (since the whole catalog vs
schema area is a bit of a mess) but it wouldn't be portable.

> I'd be willing to task myself with producing patches
> for the Pg, MySQL, and SQLite2 drivers to either make use of that attribute,
> or provide a current_schema (or maybe current_database? under Pg at least,
> schemas and db's are different) method. Which way is the right way to go here?

Generally DBI drivers should "do what the database vendors own ODBC
driver does" (or what the SQL 2003 standard mandates).

Though it seems GetSessionInfo isn't part of ODBC, it is in the SQL1999
and later standards.

I think the "right way to go here" is to add $dbh->get_session_info($type)
in a very similar way to how get_info() is handled. Patches welcome.

Tim.

Reply via email to