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 For generating 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 For generating 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 many 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 vari‐
36 able DBI_DSN. DBD::Driver::GetInfo should help a DBD author implement‐
37 ing the DBI get_info() method. Because you are just creating this
38 package, it's very unlikely that DBD::Driver already provides a good
39 implementation for get_info(). Thus you will probably connect via
40 DBD::ODBC.
41
42 Once you are sure that it is producing semi-sane data, you would typi‐
43 cally redirect the standard output to lib/DBD/Driver/GetInfo.pm, and
44 then hand edit the result. Do not forget to update your Makefile.PL
45 and MANIFEST to include this as an extra PM file that should be
46 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 val‐
54 ues 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 have to write additional subroutines for values depending on
57 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 func‐
71 tion, but you must manually transfer the code to Driver.pm.
72
74 The "write_typeinfo_pm" function in the DBI::DBD::Metadata module gen‐
75 erates on standard output the data needed for a driver's type_info_all
76 method. It also provides default implementations of the type_info_all
77 method for inclusion in the driver's main implementation file.
78
79 The driver parameter is the name of the driver for which the methods
80 will be generated; for the sake of examples, this will be "Driver".
81 Typically, the dsn parameter will be of the form "dbi:ODBC:odbc_dsn",
82 where the odbc_dsn is a DSN for one of the driver's databases. The
83 user and pass parameters are the other optional connection parameters
84 that will be provided to the DBI connect method.
85
86 Once you are sure that it is producing semi-sane data, you would typi‐
87 cally redirect the standard output to lib/DBD/Driver/TypeInfo.pm, and
88 then hand edit the result if necessary. Do not forget to update your
89 Makefile.PL and MANIFEST to include this as an extra PM file that
90 should be installed.
91
92 Please take a critical look at the data returned! ODBC drivers vary
93 dramatically in their quality.
94
95 The generator assumes that all the values are static and places these
96 values directly in the %info hash.
97
98 A possible implementation of DBD::Driver::type_info_all() may look
99 like:
100
101 sub type_info_all {
102 my ($dbh) = @_;
103 require DBD::Driver::TypeInfo;
104 return [ @$DBD::Driver::TypeInfo::type_info_all ];
105 }
106
107 Please replace Driver (or "<foo>") with the name of your driver. Note
108 that this stub function is generated for you by the write_typeinfo_pm
109 function, but you must manually transfer the code to Driver.pm.
110
112 Jonathan Leffler <jleffler@us.ibm.com> (previously <jlef‐
113 fler@informix.com>), Jochen Wiedmann <joe@ispsoft.de>, Steffen Goeldner
114 <sgoeldner@cpan.org>, and Tim Bunce <dbi-users@perl.org>.
115
116
117
118perl v5.8.8 2006-02-07 DBI::DBD::Metadata(3)