Re: Find current database name from db handle



On Feb 4, 2008 6:23 AM, Kostas Chatzikokolakis <kostas@xxxxxxxxxx> wrote:

I'm using a dbi handle that is shared between many packages in my
code. Some package might do a "USE db_name" to change the current
database of the connection. Can I retrieve the current database name
from the handle, either from DBI or from the DBD::mysql driver
(without querying the server)?

What's wrong with 'perldoc DBI'?

What's the name attribute of a database handle documented as doing?

Does it not work for you?


This was a bit churlish of me, but may I recommend reading

http://www.catb.org/~esr/faqs/smart-questions.html

which advises you on how to ask questions without incurring such ... ire.


Hello Jonathan, thanks for your reply.

From perldoc:

Name [...]
Usually (and recommended to be) the same as the "dbi:DriverName:..."
string used to connect to
the database, but with the leading "dbi:DriverName:" removed.

So Name returns the dsn used to connect, it is not meant to be the
"current" database (it's not updated when changing database by doing
"USE <db-name>"). I want something that is dynamic, similar to doing a
"SELECT DATABASE()" query in mysql, but without doing an actual query.
Sorry if I wasn't clear enough in my previous mail.


OK - fair enough. With DBD::Informix the Name is the 'DSN' supplied at
connection time. There's a separate ix_Database attribute (in the private
namespace) that gives the current database name. If you can change
databases while a connection is in progress, Name is unreliable (that's the
case on DBD::Informix, though it takes some care to make a connection
changeable). But I think you are dependent on driver properties --
different drivers do it differently.

--
Jonathan Leffler <jonathan.leffler@xxxxxxxxx> #include <disclaimer.h>
Guardian of DBD::Informix - v2007.0914 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."


Relevant Pages

  • RE: Import external data - web query
    ... Your reply for my query is very extensive, this is for importing a file from ... The data source I want isn't listed in the Select Data Source dialog box. ... information used to connect to a database. ... Check your driver First, make sure you have the right ODBC driver (Open ...
    (microsoft.public.excel.misc)
  • Re: Ada DB bindings and APQ
    ... >>I didn't like the use of handles for database objects. ... > will ensure that the connection will not go away until at least one query ... > things which can be made with a connection. ... That is different to ODBC. ...
    (comp.lang.ada)
  • RE: Posible to speed up query update with Apllication.screenupdati
    ... Don't change anything on the database side; the only question is the most ... You create a connection by sending the connect string to the ODBC driver. ... (multiple queries). ... You now execute the query (there are several ways in ADO but I usually ...
    (microsoft.public.excel.programming)
  • Re: MS Access looks for .mdb rather than Progress schema
    ... It got past looking for pub.mdb, and looks like it tried to run the query ... I also tried putting the whole thing in the connection string: ... The settings for the Merant ODBC driver for ... default connect string means a jet database. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Criteria in Database Results
    ... I copied and pasted the exact code into my custom query on ... database results and I get the following error when trying ... The following error message comes from the database driver ... Microsoft OLE DB Provider for ODBC Drivers ...
    (microsoft.public.frontpage.programming)