DBI::DBD::Metadata(3)

πŸ’– DBI::DBD::Metadata(3) πŸ’–

okay bestie, welcome to DBI::DBD::Metadata β€” the Perl module that basically does your homework for you when you're writing a DBI driver. it lives under "User Contributed Perl Documentation" and it is so useful it's giving main character energy. 🫢


✨ NAME ✨

DBI::DBD::Metadata β€” Generate the code and data for some DBI metadata methods πŸ’…


🌸 SYNOPSIS 🌸

the whole vibe here, the entire concept, the plot: you go extract metadata from a good quality ODBC driver, and then you use that to generate code and data so you can use it in your own DBI driver for the same database. it's giving "borrow the rich kid's notes", but legal. πŸ’–

to generate code to support the get_info method:

perl -MDBI::DBD::Metadata -e "write_getinfo_pm('dbi:ODBC:dsn-name','user','pass','Driver')"

perl -MDBI::DBD::Metadata -e write_getinfo_pm dbi:ODBC:foo_db username password Driver

to generate code to support the type_info method:

perl -MDBI::DBD::Metadata -e "write_typeinfo_pm('dbi:ODBC:dsn-name','user','pass','Driver')"

perl -MDBI::DBD::Metadata -e write_typeinfo_pm dbi:ODBC:dsn-name user pass Driver

where dbi:ODBC:dsn-name is the connection to use to extract the data, and Driver is the name of the driver you want the code generated for. and bestie, heads up β€” the driver name gets embedded into the output in numerous places, like it's putting its name on everything. so pick it correctly the first time, fr fr. 😭


πŸ¦‹ Generating a GetInfo package for a driver πŸ¦‹

the write_getinfo_pm in the DBI::DBD::Metadata module generates a DBD::Driver::GetInfo package on standard output. yep, straight to stdout, it does not ask. ✨

this method generates a DBD::Driver::GetInfo package from the data source you specified in the parameter list or in the environment variable DBI_DSN. DBD::Driver::GetInfo should help a DBD author implement the DBI get_info() method. and like β€” because you are just creating this package, it is very unlikely that DBD::Driver already provides a good implementation for get_info(). so you will probably connect via DBD::ODBC. that's the norm, no cap. πŸ’

once you are sure that it is producing reasonably sane data, you should typically redirect the standard output to lib/DBD/Driver/GetInfo.pm, and then hand edit the result. and do not forget to update your Makefile.PL and MANIFEST to include this as an extra PM file that should be installed. not me forgetting the MANIFEST every single time πŸ™ˆ

if you connect via DBD::ODBC, you should use version 0.38 or greater. periodt. πŸ’…

Please take a critical look at the data returned! ODBC drivers vary dramatically in their quality. like, dramatically dramatically. πŸ‘€

the generator assumes that most values are static and places these values directly in the %info hash. a few examples show the use of CODE references and the implementation via subroutines. it is very likely that you will have to write additional subroutines for values depending on the session state or server version, e.g. SQL_DBMS_VER. so don't be shocked when you gotta do extra credit, bestie. 🧚

a possible implementation of DBD::Driver::db::get_info() may look like:

sub get_info {
  my($dbh, $info_type) = @_;
  require DBD::Driver::GetInfo;
  my $v = $DBD::Driver::GetInfo::info{int($info_type)};
  $v = $v->($dbh) if ref $v eq 'CODE';
  return $v;
}

please replace Driver (or "<foo>") with the name of your driver. and note β€” this stub function is generated for you by write_getinfo_pm function, but you must manually transfer the code to Driver.pm. the generator does not do that part, that's a you task. πŸ’€


🌈 Generating a TypeInfo package for a driver 🌈

the write_typeinfo_pm function in the DBI::DBD::Metadata module generates on standard output the data needed for a driver's type_info_all method. it also provides default implementations of the type_info_all method for inclusion in the driver's main implementation file. two for one, iconic. πŸ‘‘

the driver parameter is the name of the driver for which the methods will be generated; for the sake of examples, this will be "Driver". typically, the dsn parameter will be of the form "dbi:ODBC:odbc_dsn", where the odbc_dsn is a DSN for one of the driver's databases. the user and pass parameters are the other optional connection parameters that will be provided to the DBI connect method. πŸ’œ

once you are sure that it is producing reasonably sane data, you should typically redirect the standard output to lib/DBD/Driver/TypeInfo.pm, and then hand edit the result if necessary. and again β€” do not forget to update your Makefile.PL and MANIFEST to include this as an extra PM file that should be installed. πŸŽ€

Please take a critical look at the data returned! ODBC drivers vary dramatically in their quality. same warning, same energy, same truth. πŸ”₯

the generator assumes that all the values are static and places these values directly in the %info hash. no CODE refs, just vibes and static data, fr fr. ✨

a possible implementation of DBD::Driver::type_info_all() may look like:

sub type_info_all {
  my ($dbh) = @_;
  require DBD::Driver::TypeInfo;
  return [ @$DBD::Driver::TypeInfo::type_info_all ];
}

please replace Driver (or "<foo>") with the name of your driver. and note β€” this stub function is generated for you by the write_typeinfo_pm function, but you must manually transfer the code to Driver.pm. yes, again. manually. it's a recurring theme, iykyk. πŸ˜­πŸ’…


πŸ‘‘ AUTHORS πŸ‘‘

the legends themselves, the ones who made this whole thing possible:

  • Jonathan Leffler <jleffler@us.ibm.com> (previously <jleffler@informix.com>)
  • Jochen Wiedmann <joe@ispsoft.de>
  • Steffen Goeldner <sgoeldner@cpan.org>
  • Tim Bunce <dbi-users@perl.org>

absolute icons, all four of them. bow down. 🫢🌸


okay and that's the whole page!! this doc shipped as part of Perl, perl v5.42.3, dated 2026-10-19 β€” go off, timestamp, you're doing amazing sweetie. πŸ’–βœ¨πŸŽ€πŸ¦‹

now go generate some metadata, bestie. slay. πŸ’…πŸŒˆ

πŸ“¦ where this page comes from