There isn't a specific DBI method for returning the db version although some time ago DBI added the get_info method which can be used to get db meta information. The get_info method is modeled on ODBC and is fully supported in DBD::ODBC like the following (stolen straight from DBD::ODBC's 20SqlServer.t test file):

$dbms_name = $dbh->get_info(17); ok($dbms_name, "got DBMS name: $dbms_name"); $dbms_version = $dbh->get_info(18); ok($dbms_version, "got DBMS version: $dbms_version"); $m_dbmsversion = $dbms_version; $m_dbmsversion =~ s/^(\d+).*/$1/; ok($m_dbmsversion, "got DBMS major version: $m_dbmsversion"); $driver_name = $dbh->get_info(6); ok($driver_name, "got Driver Name: $driver_name");

However, other DBDs support get_info via a rather circuitous route (see generating the get_info method) which involves running some code through DBD::ODBC and the database's ODBC driver to find the get_info values then adding the results to the DBD. As a result, sometimes the results are not as dynamic as you might like i.e., the DBD would have to update the version numbers in the get_info structure when it connects and I suspect some don't. Also, I don't believe all DBDs have added full get_info support - DBD::Oracle only just got a reworked get_info recently for instance.

If you find a DBD which fails to support the get_info values you want then you can always rt it or even better fix it yourself and send the maintainer a patch.

You might also look at the private attribute information for each DBD - see private_attribute_info.

Beyond that, you are probably left with a database/DBD specific way for each database/DBD like the select you have been shown for MySQL.


In reply to Re: Finding database version from handle? by mje
in thread Finding database version from handle? by cosmicperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.