.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "DBIx::Introspector 3pm" .TH DBIx::Introspector 3pm "2015-01-29" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DBIx::Introspector \- Detect what database you are connected to .SH "VERSION" .IX Header "VERSION" version 0.001005 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& my $d = DBIx::Introspector\->new(drivers => \*(Aq2013\-12.01\*(Aq); \& \& # standard dialects \& $d\->decorate_driver_unconnected(Pg => concat_sql => \*(Aq? || ?\*(Aq); \& $d\->decorate_driver_unconnected(SQLite => concat_sql => \*(Aq? || ?\*(Aq); \& \& # non\-standard \& $d\->decorate_driver_unconnected(MSSQL => concat_sql => \*(Aq? + ?\*(Aq); \& $d\->decorate_driver_unconnected(mysql => concat_sql => \*(AqCONCAT( ?, ? )\*(Aq); \& \& my $concat_sql = $d\->get($dbh, $dsn, \*(Aqconcat_sql\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`DBIx::Introspector\*(C'\fR is a module factored out of the DBIx::Class database detection code. Most code that needs to detect which database it is connected to assumes that there is a one-to-one mapping from database drivers to database engines. Unfortunately reality is rarely that simple. For instance, \&\s-1DBD::ODBC\s0 is typically used to connect to \s-1SQL\s0 Server, but \s-1ODBC\s0 can be used to connect to PostgreSQL, MySQL, and Oracle. Additionally, while \s-1ODBC\s0 is the most common way to connect to \s-1SQL\s0 Server, it is not the only option, as \s-1DBD::ADO\s0 can also be used. .PP \&\f(CW\*(C`DBIx::Introspector\*(C'\fR can correctly detect which database you are connected to, because it was factored out of a complex, working codebase. On top of that it has been written to be very extensible. So if you needed to detect which version of your given database you are connected to that would not be difficult. .PP Furthermore, \f(CW\*(C`DBIx::Introspector\*(C'\fR does its best to try to detect information based on the dsn you give it if you have not yet connected, so you can possibly avoid connection or at least defer connection. .SH "METHODS" .IX Header "METHODS" .ie n .SS """add_driver""" .el .SS "\f(CWadd_driver\fP" .IX Subsection "add_driver" .Vb 7 \& $dbii\->add_driver({ \& name => \*(AqPg\*(Aq, \& parents => [\*(AqDBI\*(Aq], \& unconnected_options => { \& concat_sql => \*(Aq? || ?\*(Aq, \& random_func => \*(AqRANDOM()\*(Aq, \& }) .Ve .PP Takes a hashref defining a new driver . .ie n .SS """replace_driver""" .el .SS "\f(CWreplace_driver\fP" .IX Subsection "replace_driver" .Vb 7 \& $dbii\->replace_driver({ \& name => \*(AqPg\*(Aq, \& parents => [\*(AqDBI\*(Aq], \& unconnected_options => { \& concat_sql => \*(Aq? || ?\*(Aq, \& random_func => \*(AqRANDOM()\*(Aq, \& }) .Ve .PP Takes a hashref replacing an existing driver . Replaces the driver already defined with the same name. .ie n .SS """decorate_driver_connected""" .el .SS "\f(CWdecorate_driver_connected\fP" .IX Subsection "decorate_driver_connected" .Vb 1 \& $dbii\->decorate_driver_connected(\*(AqMSSQL\*(Aq, \*(Aqconcat_sql\*(Aq, \*(Aq? + ?\*(Aq) .Ve .PP Takes a \f(CW\*(C`driver name\*(C'\fR, \f(CW\*(C`key\*(C'\fR and a \f(CW\*(C`value\*(C'\fR. The \f(CW\*(C`key value\*(C'\fR pair will be inserted into the driver's \f(CW\*(C`connected_options\*(C'\fR. .ie n .SS """decorate_driver_unconnected""" .el .SS "\f(CWdecorate_driver_unconnected\fP" .IX Subsection "decorate_driver_unconnected" .Vb 1 \& $dbii\->decorate_driver_unconnected(\*(AqSQLite\*(Aq, \*(Aqconcat_sql\*(Aq, \*(Aq? || ?\*(Aq) .Ve .PP Takes a \f(CW\*(C`driver name\*(C'\fR, \f(CW\*(C`key\*(C'\fR and a \f(CW\*(C`value\*(C'\fR. The \f(CW\*(C`key value\*(C'\fR pair will be inserted into the driver's \f(CW\*(C`unconnected_options\*(C'\fR. .ie n .SS """get""" .el .SS "\f(CWget\fP" .IX Subsection "get" .Vb 1 \& $dbii\->get($dbh, $dsn, \*(Aqconcat_sql\*(Aq) .Ve .PP Takes a \f(CW\*(C`dbh\*(C'\fR, \f(CW\*(C`dsn\*(C'\fR, \f(CW\*(C`key\*(C'\fR, and optionally a hashref of \f(CW\*(C`options\*(C'\fR. .PP The \f(CW\*(C`dbh\*(C'\fR can be a coderef returning a \f(CW\*(C`dbh\*(C'\fR. If you provide the \&\f(CW\*(C`dbh_fallback_connect\*(C'\fR option it will be used to connect the \f(CW\*(C`dbh\*(C'\fR if it is not already connected and then queried, if the \f(CW\*(C`dsn\*(C'\fR was insufficient. .PP So for example, one might do: .PP .Vb 4 \& my $dbh; \& $dbii\->get(sub { $dbh }, $dsn, \*(Aqconcat_sql\*(Aq, { \& dbh_fallback_connect => sub { $dbh = DBI\->connect($dsn, $user, $pass) }, \& }); .Ve .PP Which will only connect if it has to, like if the user is using the \f(CW\*(C`DBD::ODBC\*(C'\fR driver to connect. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .ie n .SS """drivers""" .el .SS "\f(CWdrivers\fP" .IX Subsection "drivers" This has no default and is required, though a sane defaultish value does exist. .PP Currently there is one predefined set of drivers, named \f(CW\*(C`2013\-12.01\*(C'\fR. If drivers or facts or just the general structure of drivers changes they will always be as a new named set of drivers. \f(CW\*(C`2013\-12.01\*(C'\fR matches the 0.08250 release of DBIx::Class and probably many previous and following releases. .PP If you need to define it from scratch, you can just pass an arrayref of drivers; see the \*(L"\s-1DRIVER DEFINITION\*(R"\s0 section on what is required for that. But generally it will look something like this (from the tests): .PP .Vb 10 \& my $d = DBIx::Introspector\->new( \& drivers => [ map DBIx::Introspector::Driver\->new($_), \& { \& name => \*(AqDBI\*(Aq, \& connected_determination_strategy => sub { $_[1]\->{Driver}{Name} }, \& unconnected_determination_strategy => sub { \& my $dsn = $_[1] || $ENV{DBI_DSN} || \*(Aq\*(Aq; \& my ($driver) = $dsn =~ /dbi:([^:]+):/i; \& $driver ||= $ENV{DBI_DRIVER}; \& return $driver \& }, \& }, \& { \& name => \*(AqSQLite\*(Aq, \& parents => [\*(AqDBI\*(Aq], \& connected_determination_strategy => sub { \& my ($v) = $_[1]\->selectrow_array(\*(AqSELECT "value" FROM "a"\*(Aq); \& return "SQLite$v" \& }, \& connected_options => { \& bar => sub { 2 }, \& }, \& unconnected_options => { \& borg => sub { \*(Aqmagic ham\*(Aq }, \& }, \& }, \& { name => \*(AqSQLite1\*(Aq, parents => [\*(AqSQLite\*(Aq] }, \& { name => \*(AqSQLite2\*(Aq, parents => [\*(AqSQLite\*(Aq] }, \& ] \& ); .Ve .SH "DRIVER DEFINITION" .IX Header "DRIVER DEFINITION" Drivers (\f(CW\*(C`DBIx::Introspector::Driver\*(C'\fR objects) have the following six attributes: .ie n .SS """name""" .el .SS "\f(CWname\fP" .IX Subsection "name" Required. Must be unique among the drivers contained in the introspector. .ie n .SS """parents""" .el .SS "\f(CWparents\fP" .IX Subsection "parents" Arrayref of parent drivers. This allows parent drivers to implement common options among children. So for example on might define a driver for each version of PostgreSQL, and have a parent driver that they all use for common base info. .ie n .SS """connected_determination_strategy""" .el .SS "\f(CWconnected_determination_strategy\fP" .IX Subsection "connected_determination_strategy" This is a code reference that is called as a method on the driver with the \&\f(CW\*(C`dbh\*(C'\fR as the first argument and an optional \f(CW\*(C`dsn\*(C'\fR as the second argument. It should return a driver name. .ie n .SS """unconnected_determination_strategy""" .el .SS "\f(CWunconnected_determination_strategy\fP" .IX Subsection "unconnected_determination_strategy" This is a code reference that is called as a method on the driver with the \&\f(CW\*(C`dsn\*(C'\fR as the first argument. It should return a driver name. .ie n .SS """connected_options""" .el .SS "\f(CWconnected_options\fP" .IX Subsection "connected_options" Hashref of \f(CW\*(C`key value\*(C'\fR pairs for detecting information based on the \&\f(CW\*(C`dbh\*(C'\fR. A value that is not a code reference is returned directly, though I suggest non-coderefs all go in the \*(L"unconnected_options\*(R" so that they may be used without connecting if possilbe. .PP If a code reference is passed it will get called as a method on the driver with the following list of values: .ie n .IP """dbh""" 2 .el .IP "\f(CWdbh\fR" 2 .IX Item "dbh" This is the connected \f(CW\*(C`dbh\*(C'\fR that you can use to introspect the database. .ie n .IP """dsn""" 2 .el .IP "\f(CWdsn\fR" 2 .IX Item "dsn" This is the \f(CW\*(C`dsn\*(C'\fR passed to \*(L"get\*(R", possibly undefined. .ie n .SS """unconnected_options""" .el .SS "\f(CWunconnected_options\fP" .IX Subsection "unconnected_options" Hashref of \f(CW\*(C`key value\*(C'\fR pairs for detecting information based on the \&\f(CW\*(C`dsn\*(C'\fR. A value that is not a code reference is returned directly. .PP If a code reference is passed it will get called as a method on the driver with the following list value: .ie n .IP """dsn""" 2 .el .IP "\f(CWdsn\fR" 2 .IX Item "dsn" This is the connected \f(CW\*(C`dsn\*(C'\fR that you can use to introspect the database. .SH "AUTHOR" .IX Header "AUTHOR" Arthur Axel \*(L"fREW\*(R" Schmidt .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2015 by Arthur Axel \*(L"fREW\*(R" Schmidt. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.