1DBI::DBD::Metadata(3) User Contributed Perl DocumentationDBI::DBD::Metadata(3)
2
3
4
6 DBI::DBD::Metadata - Generate the code and data for some DBI metadata
7 methods
8
10 The idea is to extract metadata information from a good quality ODBC
11 driver and use it to generate code and data to use in your own DBI
12 driver for the same database.
13
14 To generate code to support the get_info method:
15
16 perl -MDBI::DBD::Metadata -e "write_getinfo_pm('dbi:ODBC:dsn-name','user','pass','Driver')"
17
18 perl -MDBI::DBD::Metadata -e write_getinfo_pm dbi:ODBC:foo_db username password Driver
19
20 To generate code to support the type_info method:
21
22 perl -MDBI::DBD::Metadata -e "write_typeinfo_pm('dbi:ODBC:dsn-name','user','pass','Driver')"
23
24 perl -MDBI::DBD::Metadata -e write_typeinfo_pm dbi:ODBC:dsn-name user pass Driver
25
26 Where "dbi:ODBC:dsn-name" is the connection to use to extract the data,
27 and "Driver" is the name of the driver you want the code generated for
28 (the driver name gets embedded into the output in numerous places).
29
31 The "write_getinfo_pm" in the DBI::DBD::Metadata module generates a
32 DBD::Driver::GetInfo package on standard output.
33
34 This method generates a DBD::Driver::GetInfo package from the data
35 source you specified in the parameter list or in the environment
36 variable DBI_DSN. DBD::Driver::GetInfo should help a DBD author
37 implement the DBI get_info() method. Because you are just creating
38 this package, it is very unlikely that DBD::Driver already provides a
39 good implementation for get_info(). Thus you will probably connect via
40 DBD::ODBC.
41
42 Once you are sure that it is producing reasonably sane data, you should
43 typically redirect the standard output to lib/DBD/Driver/GetInfo.pm,
44 and then hand edit the result. Do not forget to update your
45 Makefile.PL and MANIFEST to include this as an extra PM file that
46 should be installed.
47
48 If you connect via DBD::ODBC, you should use version 0.38 or greater;
49
50 Please take a critical look at the data returned! ODBC drivers vary
51 dramatically in their quality.
52
53 The generator assumes that most values are static and places these
54 values directly in the %info hash. A few examples show the use of CODE
55 references and the implementation via subroutines. It is very likely
56 that you will have to write additional subroutines for values depending
57 on the session state or server version, e.g. SQL_DBMS_VER.
58
59 A possible implementation of DBD::Driver::db::get_info() may look like:
60
61 sub get_info {
62 my($dbh, $info_type) = @_;
63 require DBD::Driver::GetInfo;
64 my $v = $DBD::Driver::GetInfo::info{int($info_type)};
65 $v = $v->($dbh) if ref $v eq 'CODE';
66 return $v;
67 }
68
69 Please replace Driver (or "<foo>") with the name of your driver. Note
70 that this stub function is generated for you by write_getinfo_pm
71 function, but you must manually transfer the code to Driver.pm.
72
74 The "write_typeinfo_pm" function in the DBI::DBD::Metadata module
75 generates on standard output the data needed for a driver's
76 type_info_all method. It also provides default implementations of the
77 type_info_all method for inclusion in the driver's main implementation
78 file.
79
80 The driver parameter is the name of the driver for which the methods
81 will be generated; for the sake of examples, this will be "Driver".
82 Typically, the dsn parameter will be of the form "dbi:ODBC:odbc_dsn",
83 where the odbc_dsn is a DSN for one of the driver's databases. The
84 user and pass parameters are the other optional connection parameters
85 that will be provided to the DBI connect method.
86
87 Once you are sure that it is producing reasonably sane data, you should
88 typically redirect the standard output to lib/DBD/Driver/TypeInfo.pm,
89 and then hand edit the result if necessary. Do not forget to update
90 your Makefile.PL and MANIFEST to include this as an extra PM file that
91 should be installed.
92
93 Please take a critical look at the data returned! ODBC drivers vary
94 dramatically in their quality.
95
96 The generator assumes that all the values are static and places these
97 values directly in the %info hash.
98
99 A possible implementation of DBD::Driver::type_info_all() may look
100 like:
101
102 sub type_info_all {
103 my ($dbh) = @_;
104 require DBD::Driver::TypeInfo;
105 return [ @$DBD::Driver::TypeInfo::type_info_all ];
106 }
107
108 Please replace Driver (or "<foo>") with the name of your driver. Note
109 that this stub function is generated for you by the write_typeinfo_pm
110 function, but you must manually transfer the code to Driver.pm.
111
113 Jonathan Leffler <jleffler@us.ibm.com> (previously
114 <jleffler@informix.com>), Jochen Wiedmann <joe@ispsoft.de>, Steffen
115 Goeldner <sgoeldner@cpan.org>, and Tim Bunce <dbi-users@perl.org>.
116
117
118
119perl v5.36.0 2023-01-20 DBI::DBD::Metadata(3)