in reply to Finding database version from handle?
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.
|
|---|