Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,
consider the following code and output:

#!/usr/bin/perl use strict; use warnings; use DBI; my @db_drivers = DBI->available_drivers(); foreach my $db_driver (@db_drivers) { print "$db_driver\n"; my @data_sources = DBI->data_sources($db_driver); print "\t", join(", ",@data_sources), "\n"; }

Output:

$ perl DBI_data_sources.pl DBM DBI:DBM:f_dir=. ExampleP dbi:ExampleP:dir=. File DBI:File:f_dir=. Gofer Proxy SQLite Sponge

I am aware of DBI->data_sources

"Note that many drivers have no way of knowing what data sources might be available for it. These drivers return an empty or incomplete list or may require driver-specific attributes."
and would like to see a real world (tm) example output with defined values for data_sources.

Thanks.

Replies are listed 'Best First'.
Re: Is DBI->data_sources($db_driver) useless?
by roboticus (Chancellor) on Mar 11, 2009 at 20:42 UTC

    Works mostly fine here. Below is the output from your program (except that I snipped out the DBM and File driver results, and the @INC path from the error message.)

    $ ./749992.pl ExampleP dbi:ExampleP:dir=. Gofer ODBC dbi:ODBC:pci_PITS_1, dbi:ODBC:mrchact, dbi:ODBC:VisiWork, dbi: +ODBC:Jigzup, dbi:ODBC:ATHENA, dbi:ODBC:BASE, dbi:ODBC:UniCRE, dbo:ODB +C:DMap Proxy install_driver(Proxy) failed: Can't locate RPC/PlClient.pm in @INC (@I +NC contains: <SNIP>) at /usr/lib/perl5/site_perl/5.10/i686-cygwin/DBD +/Proxy.pm line 29. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.10/i68 +6-cygwin/DBD/Proxy.pm line 29. Compilation failed in require at (eval 18) line 3. Perhaps a module that DBD::Proxy requires hasn't been fully installed at ./749992.pl line 13
    ...roboticus
Re: Is DBI->data_sources($db_driver) useless?
by jethro (Monsignor) on Mar 11, 2009 at 20:54 UTC

    Another example from a debian box:

    DBM DBI:DBM:f_dir=., DBI:DBM:f_dir=.X11-unix, DBI:DBM:f_dir=.ICE-u +nix ExampleP dbi:ExampleP:dir=. File DBI:DBM:f_dir=., DBI:DBM:f_dir=.X11-unix, DBI:DBM:f_dir=.ICE-u +nix Proxy Sponge mysql

    The mysql driver might have been able to find /var/run/mysqld/mysqld.sock, but obviously it didn't. And I have to confess I don't know why .X11-unix and .ICE-unix (I guess this referes to the socket dirs in /tmp) turned up as DBM data sources

Re: Is DBI->data_sources($db_driver) useless?
by trwww (Priest) on Mar 12, 2009 at 02:19 UTC

    Hello,

    The API you describe is a convenient interface to Oracle's tnsnames.ora

    I seem to recall it working well for some microsoft based datasources, also.

    regards,

Re: Is DBI->data_sources($db_driver) useless?
by mje (Curate) on Mar 12, 2009 at 11:22 UTC

    DBD::ODBC should be able to return a list of data sources so long as DBD::ODBC is built against an ODBC driver manager. The ODBC spec includes a SQLDataSources API and I know this works with MS ODBC Driver manager and the unixODBC driver manager. Few other DBDs return much.