.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" 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 >0, 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 "URI::db 3pm" .TH URI::db 3pm "2022-11-19" "perl v5.36.0" "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" .IX Header "Name" URI::db \- Database URIs .SH "Synopsis" .IX Header "Synopsis" .Vb 4 \& use URI; \& my $db_uri = URI\->new(\*(Aqdb:pg://user@localhost\*(Aq); \& my $pg_uri = URI\->new(\*(Aqpostgres://example.com/template1\*(Aq); \& my $sl_uri = URI\->new(\*(Aqsqlite:/var/db/widgets.db\*(Aq); .Ve .SH "Description" .IX Header "Description" This class provides support for database URIs. They're inspired by \&\s-1JDBC\s0 URIs and PostgreSQL URIs , though they're a bit more formal. The specification for their format is documented in \fI\s-1README\s0.md\fR . .PP \&\fBWarning:\fR This is an alpha release. I will do my best to preserve functionality going forward, especially as Sqitch uses this module. However, as the database \s-1URI\s0 specification moves forward, changes \&\fImay\fR require backwards-incompatible changes. Caveat Hackor. .PP \fIFormat\fR .IX Subsection "Format" .PP A database \s-1URI\s0 is made up of these parts: .PP .Vb 1 \& db:engine:[//[user[:password]@][host][:port]/][dbname][?params][#fragment] .Ve .ie n .IP """db""" 4 .el .IP "\f(CWdb\fR" 4 .IX Item "db" The literal string \f(CW\*(C`db\*(C'\fR is the scheme that defines a database \s-1URI.\s0 Optional for well-known engines. .ie n .IP """engine""" 4 .el .IP "\f(CWengine\fR" 4 .IX Item "engine" A string identifying the database engine. .ie n .IP """user""" 4 .el .IP "\f(CWuser\fR" 4 .IX Item "user" The user name to use when connecting to the database. .ie n .IP """password""" 4 .el .IP "\f(CWpassword\fR" 4 .IX Item "password" The password to use when connecting to the database. .ie n .IP """host""" 4 .el .IP "\f(CWhost\fR" 4 .IX Item "host" The host address to connect to. .ie n .IP """port""" 4 .el .IP "\f(CWport\fR" 4 .IX Item "port" The network port to connect to. .ie n .IP """dbname""" 4 .el .IP "\f(CWdbname\fR" 4 .IX Item "dbname" The name of the database. For some engines, this will be a file name, in which case it may be a complete or local path, as appropriate. .ie n .IP """params""" 4 .el .IP "\f(CWparams\fR" 4 .IX Item "params" A URI-standard \s-1GET\s0 query string representing additional parameters to be passed to the engine. .ie n .IP """fragment""" 4 .el .IP "\f(CWfragment\fR" 4 .IX Item "fragment" Identifies a database part, such as a table or view. .PP \fIExamples\fR .IX Subsection "Examples" .PP Some examples: .IP "\(bu" 4 \&\f(CW\*(C`db:sqlite\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:sqlite:dbname\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:sqlite:/path/to/some.db\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`sqlite:../relative.db\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:firebird://localhost/%2Fpath/to/some.db\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:firebird://localhost//path/to/some.db\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`firebird://localhost/relative.db\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:pg://\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:pg://localhost\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:pg://localhost:5433\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:pg://localhost/mydb\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:pg://user@localhost\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:pg://user:secret@/mydb\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`pg:///mydb\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`pg://other@localhost/otherdb?connect_timeout=10&application_name=myapp\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db://localhost/mydb\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`db:unknown://example.com/mydb\*(C'\fR .SH "Interface" .IX Header "Interface" The following differences exist compared to the \f(CW\*(C`URI\*(C'\fR class interface: .SS "Class Method" .IX Subsection "Class Method" \fI\f(CI\*(C`default_port\*(C'\fI\fR .IX Subsection "default_port" .PP Returns the default port for the engine. This is a class method value defined by each recognized \s-1URI\s0 engine. .SS "Constructors" .IX Subsection "Constructors" \fI\f(CI\*(C`new\*(C'\fI\fR .IX Subsection "new" .PP .Vb 2 \& my $uri = URI::db\->new($string); \& my $uri = URI::db\->new($string, $base); .Ve .PP Always returns a URI::db object. \f(CW$base\fR may be another \s-1URI\s0 object or string. Unlike in \s-1URI\s0's \f(CW\*(C`new()\*(C'\fR, the scheme will always be applied to the \s-1URI\s0 if it does not already have one. .SS "Accessors" .IX Subsection "Accessors" \fI\f(CI\*(C`scheme\*(C'\fI\fR .IX Subsection "scheme" .PP .Vb 2 \& my $scheme = $uri\->scheme; \& $uri\->scheme( $new_scheme ); .Ve .PP Gets or sets the scheme part of the \s-1URI.\s0 For \f(CW\*(C`db:\*(C'\fR URIs, the scheme cannot be changed to any value other than \*(L"db\*(R" (or any case variation thereof). For non\-\f(CW\*(C`db:\*(C'\fR URIs, the scheme may be changed to any value, though the \s-1URI\s0 object may no longer be a database \s-1URI.\s0 .PP \fI\f(CI\*(C`engine\*(C'\fI\fR .IX Subsection "engine" .PP .Vb 2 \& my $engine = $uri\->engine; \& $uri\->engine( $new_engine ); .Ve .PP Gets or sets the engine part of the \s-1URI,\s0 which may be any valid \s-1URI\s0 scheme value, though recognized engines provide additional context, such as the \&\f(CW\*(C`default_port()\*(C'\fR and a driver-specific \f(CW\*(C`dbi_dsn()\*(C'\fR. .PP If called with an argument, it updates the engine, possibly changing the class of the \s-1URI,\s0 and returns the old engine value. .PP \fI\f(CI\*(C`canonical_engine\*(C'\fI\fR .IX Subsection "canonical_engine" .PP .Vb 1 \& my $canonical_engine = $uri\->canonical_engine; .Ve .PP Returns the canonical engine. A number of engine names are aliases for other engines. This method will return the non-aliased engine name. For example, the \&\f(CW\*(C`postgres\*(C'\fR engine will return the canonical engine \f(CW\*(C`pg\*(C'\fR, the \f(CW\*(C`sqlite3\*(C'\fR returns the canonical engine \f(CW\*(C`sqlite\*(C'\fR, and \f(CW\*(C`maria\*(C'\fR returns the canonical engine \f(CW\*(C`mysql\*(C'\fR. .PP \fI\f(CI\*(C`dbname\*(C'\fI\fR .IX Subsection "dbname" .PP .Vb 2 \& my $dbname = $uri\->dbname; \& $uri\->dbname( $new_dbname ); .Ve .PP Gets or sets the name of the database. If called with an argument, the path will also be updated. .PP \fI\f(CI\*(C`host\*(C'\fI\fR .IX Subsection "host" .PP .Vb 2 \& my $host = $uri\->host; \& $uri\->host( $new_host ); .Ve .PP Gets or sets the host to connect to. .PP \fI\f(CI\*(C`port\*(C'\fI\fR .IX Subsection "port" .PP .Vb 2 \& my $port = $uri\->port; \& $uri\->port( $new_port ); .Ve .PP Gets or sets the port to connect to. .PP \fI\f(CI\*(C`user\*(C'\fI\fR .IX Subsection "user" .PP .Vb 2 \& my $user = $uri\->user; \& $uri\->user( $new_user ); .Ve .PP Gets or sets the user name. .PP \fI\f(CI\*(C`password\*(C'\fI\fR .IX Subsection "password" .PP .Vb 2 \& my $password = $uri\->password; \& $uri\->password( $new_password ); .Ve .PP Gets or sets the password. .PP \fI\f(CI\*(C`uri\*(C'\fI\fR .IX Subsection "uri" .PP Returns the underlying engine \s-1URI.\s0 For URIs starting with \f(CW\*(C`db:\*(C'\fR, this will be the \s-1URI\s0 that follows. For database URIs without \f(CW\*(C`db:\*(C'\fR, the \s-1URI\s0 itself will be returned. .SS "Instance Methods" .IX Subsection "Instance Methods" \fI\f(CI\*(C`has_recognized_engine\*(C'\fI\fR .IX Subsection "has_recognized_engine" .PP .Vb 1 \& my $has_recognized_engine = $uri\->has_recognized_engine; .Ve .PP Returns true if the engine is recognized by URI::db, and false if it is not. A recognized engine is simply one that inherits from \f(CW\*(C`URI::_db\*(C'\fR. .PP \fI\f(CI\*(C`query_params\*(C'\fI\fR .IX Subsection "query_params" .PP .Vb 1 \& my @params = $uri\->query_params; .Ve .PP Returns a list of key/value pairs representing all query parameters. Parameters specified more than once will be returned more than once, so avoid assigning to a hash. If you want a hash, use URI::QueryParam's \&\f(CW\*(C`query_from_hash()\*(C'\fR, where duplicate keys lead to an array of values for that key: .PP .Vb 2 \& use URI::QueryParam; \& my $params = $uri\->query_form_hash; .Ve .PP \fI\f(CI\*(C`dbi_driver\*(C'\fI\fR .IX Subsection "dbi_driver" .PP .Vb 3 \& if ( my $driver = $uri\->dbi_driver ) { \& eval "require DBD::$driver" or die; \& } .Ve .PP Returns a string representing the \s-1DBI\s0 driver name for the database engine, if one is known. Returns \f(CW\*(C`undef\*(C'\fR if no driver is known. .PP \fI\f(CI\*(C`dbi_dsn\*(C'\fI\fR .IX Subsection "dbi_dsn" .PP .Vb 1 \& DBI\->connect( $uri\->dbi_dsn, $uri\->user, $uri\->password ); .Ve .PP Returns a \s-1DBI\s0 \s-1DSN\s0 appropriate for use in a call to \f(CW\*(C`DBI\->connect\*(C'\fR. The attributes will usually be pulled from the \s-1URI\s0 host name, port, and database name, as well as the query parameters. If no driver is known for the \s-1URI,\s0 the \&\f(CW\*(C`dbi:$driver:\*(C'\fR part of the \s-1DSN\s0 will be omitted, in which case you can use the \&\f(CW$DBI_DRIVER\fR environment variable to identify an appropriate driver. If the \&\s-1URI\s0 supports multiple drivers, pass the name of the one you want to \&\f(CW\*(C`dbi_dsn()\*(C'\fR. Currently only URI::myssql supports alternate drivers, \s-1ADO, ODBC,\s0 or Sybase. Otherwise, each database \s-1URI\s0 does its best to create a valid \&\s-1DBI DSN.\s0 Some examples: .PP .Vb 7 \& | URI | DSN | \& |\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-| \& | db:pg:try | dbi:Pg:dbname=try | \& | db:mysql://localhost:33/foo | dbi:mysql:host=localhost;port=33;database=foo | \& | db:db2://localhost:33/foo | dbi:DB2:HOSTNAME=localhost;PORT=33;DATABASE=foo | \& | db:vertica:dbadmin | dbi:ODBC:DSN=dbadmin | \& | db:mssql://foo.com/pubs?Driver=MSSQL | dbi:ODBC:Host=foo.com;Database=pubs;Driver=MSSQL | .Ve .PP \fI\f(CI\*(C`dbi_params\*(C'\fI\fR .IX Subsection "dbi_params" .PP .Vb 1 \& my @params = $uri\->dbi_params; .Ve .PP Returns a list of key/value pairs used as parameters in the \s-1DBI\s0 \s-1DSN,\s0 including query parameters. Parameters specified more than once will be returned more than once, so avoid assigning to a hash. .PP \fI\f(CI\*(C`abs\*(C'\fI\fR .IX Subsection "abs" .PP .Vb 1 \& my $abs = $uri\->abs( $base_uri ); .Ve .PP For \f(CW\*(C`db:\*(C'\fR URIs, simply returns the URI::db object itself. For Non\-\f(CW\*(C`db:\*(C'\fR URIs, the behavior is the same as for \s-1URI\s0 including respect for \&\f(CW$URI::ABS_ALLOW_RELATIVE_SCHEME\fR. .PP \fI\f(CI\*(C`rel\*(C'\fI\fR .IX Subsection "rel" .PP .Vb 1 \& my $rel = $uri\->rel( $base_uri ); .Ve .PP For \f(CW\*(C`db:\*(C'\fR URIs, simply returns the URI::db object itself. For Non\-\f(CW\*(C`db:\*(C'\fR URIs, the behavior is the same as for \s-1URI\s0. .PP \fI\f(CI\*(C`canonical\*(C'\fI\fR .IX Subsection "canonical" .PP .Vb 1 \& my $canonical_uri = $uri\->canonical; .Ve .PP Returns a normalized version of the \s-1URI.\s0 This behavior is the same for other URIs, except that the engine will be replaced with the value of \&\f(CW\*(C`canonical_engine\*(C'\fR if it is not already the canonical engine. .SH "Support" .IX Header "Support" This module is stored in an open GitHub repository . Feel free to fork and contribute! .PP Please file bug reports via GitHub Issues or by sending mail to bug\-URI\-db@rt.cpan.org . .SH "Author" .IX Header "Author" David E. Wheeler .SH "Copyright and License" .IX Header "Copyright and License" Copyright (c) 2013\-2016 David E. Wheeler. Some Rights Reserved. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.