Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please make DBI::Const::GetInfoType and %GetInfoType hash public #65

Open
pali opened this issue May 22, 2018 · 9 comments
Open

Please make DBI::Const::GetInfoType and %GetInfoType hash public #65

pali opened this issue May 22, 2018 · 9 comments

Comments

@pali
Copy link
Member

pali commented May 22, 2018

%GetInfoType hash from the DBI::Const::GetInfoType package provides mapping from string identifiers to DBI get_info numeric values. But documentation says this package is "new" and "nothing what is written here is guaranteed". Which means that it is not ready for public API usage and for stable applications.

Package DBI::Const::GetInfo::ODBC is even more strict and its documentation contains: "The API for this module is private and subject to change.". So is not for public usage too.

I would really like to use human readable identifiers (e.g. SQL_DBMS_VER) instead of magic number 18.

So can you please make current API of the %GetInfoType hash public and reflect it into DBI::Const::GetInfoType documentation?

E.g. code:

my $database_name = $dbh->get_info($GetInfoType{SQL_DBMS_NAME});

is more readable as:

my $database_name = $dbh->get_info(17);
@timbunce
Copy link
Member

I agree with the general need. I've wanted the same myself before.

Rather than exporting the hash, and leaving people at risk of typos, I'd prefer a solution that lets code declare the constants that are needed. Something like:

use ...mumble... qw($SQL_DBMS_NAME);

my $database_name = $dbh->get_info($SQL_DBMS_NAME);

Adding a trivial import() method could enable that.

@pali
Copy link
Member Author

pali commented May 26, 2018

Or those numbers can be contant perl functions (not variables) like for SQL_INTEGER, SQL_DOUBLE which are exported by :sql_types.

@timbunce
Copy link
Member

Yes, that would be more consistent.

@pali
Copy link
Member Author

pali commented Jun 4, 2018

So what about use DBI qw(:sql_info_types) to export all those constant functions like SQL_DBMS_NAME and then use it as my $database_name = $dbh->get_info(SQL_DBMS_NAME);?

@timbunce
Copy link
Member

timbunce commented Jun 5, 2018

I don't think that's worth the cost of supporting in the DBI package itself given there there are many values and few would be used.

It should be easy enough to add to DBI::Const::GetInfoType though:

use DBI::Const::GetInfoType qw(SQL_DBMS_NAME);

by adding an import method into lib/DBI/Const/GetInfoType.pm

@pali
Copy link
Member Author

pali commented Jun 8, 2018

Usage use DBI::Const::GetInfoType qw(SQL_DBMS_NAME); should be enough... Will you prepare this extension for import method together with updating documentation?

@pali
Copy link
Member Author

pali commented Jun 8, 2018

Anyway, DBI documentation already says to use %GetInfoType hash:

https://metacpan.org/pod/DBI#get_info

The DBI::Const::GetInfoType module exports a %GetInfoType hash that can be used to map info type names to numbers. For example:

$database_version = $dbh->get_info( $GetInfoType{SQL_DBMS_VER} );

The names are a merging of the ANSI and ODBC standards (which differ in some cases). See DBI::Const::GetInfoType for more details.

@pali
Copy link
Member Author

pali commented Nov 16, 2018

@timbunce Are you going to add import method for lib/DBI/Const/GetInfoType.pm?

@timbunce
Copy link
Member

I'd welcome a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants