.\" 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 .\" ======================================================================== .\" .IX Title "Data::Phrasebook::SQL 3pm" .TH Data::Phrasebook::SQL 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" Data::Phrasebook::SQL \- The SQL/DBI Phrasebook Model. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Data::Phrasebook; \& use DBI; \& \& my $dbh = DBI\->connect(...); \& \& my $book = Data::Phrasebook\->new( \& class => \*(AqSQL\*(Aq, \& dbh => $dbh, \& file => \*(Aqqueries.txt\*(Aq, \& ); \& my $q = $book\->query( \*(Aqfind_author\*(Aq, { \& author => "Lance Parkin" \& }); \& while ( my $row = $q\->fetchrow_hashref ) { \& print "He wrote $row\->{title}\en"; \& } \& $q\->finish; .Ve .PP \&\fIqueries.txt\fR: .PP .Vb 1 \& find_author=select title,author from books where author = :author .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" In order to make use of features like placeholders in \s-1DBI\s0 in conjunction with phrasebooks, it's helpful to have a phrasebook be somewhat more aware of how \s-1DBI\s0 operates. Thus, you get \f(CW\*(C`Data::Phrasebook::SQL\*(C'\fR. .PP \&\f(CW\*(C`Data::Phrasebook::SQL\*(C'\fR has knowledge of how \s-1DBI\s0 works and creates and executes your queries appropriately. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .SS "new" .IX Subsection "new" Not to be accessed directly, but via the parent Data::Phrasebook, by specifying the class as \s-1SQL.\s0 .PP Additional arguments to those described in Data::Phrasebook::Generic are: .IP "\(bu" 4 \&\f(CW\*(C`dbh\*(C'\fR \- a \s-1DBI\s0 database handle. .SH "METHODS" .IX Header "METHODS" .SS "dbh" .IX Subsection "dbh" Set, or get, the current \s-1DBI\s0 handle. .SS "query" .IX Subsection "query" Constructs a Data::Phrasebook::SQL::Query object from a template. Takes at least one argument, this being the identifier for the query. The identifier is used as a key into the phrasebook \f(CW\*(C`file\*(C'\fR. A second argument can be provided, which is an optional hashref of key to value mappings. .PP If phrasebook has a \s-1YAML\s0 source looking much like the following: .PP .Vb 3 \& \-\-\- \& find_author: \& sql: select class,title,author from books where author = :author .Ve .PP You could write: .PP .Vb 1 \& my $q = $book\->query( \*(Aqfind_author\*(Aq ); \& \& OR \& \& my $q = $book\->query( \*(Aqfind_author\*(Aq, { \& author => \*(AqLance Parkin\*(Aq \& } ); \& \& OR \& \& my $author = \*(AqLance Parkin\*(Aq; \& my $q = $book\->query( \*(Aqfind_author\*(Aq, { \& author => \e$author, \& } ); \& \& # sql = select class,title,author from books where author = ? \& # args = \*(AqLance Parkin\*(Aq .Ve .PP In the above examples, the parameters are bound to the \s-1SQL\s0 using the bind parameters functionality. This is more efficient in most cases where the same \s-1SQL\s0 is reused with different values for fields. .PP However, not all \s-1SQL\s0 statements just need to bind parameters, some may require the ability to replace parameters, such as a field list. .PP .Vb 3 \& \-\-\- \& find_author: \& sql: select :fields from books where author = :author \& \& my $q = $book\->query( \*(Aqfind_author\*(Aq, \& replace => { fields => \*(Aqclass,title,author\*(Aq }, \& bind => { author => \*(AqLance Parkin\*(Aq } \& ); \& \& # sql = select class,title,author from books where author = ? \& # args = \*(AqLance Parkin\*(Aq .Ve .PP In all instances, if the \s-1SQL\s0 template requested does not exist or has no definition, then an error will be thrown. .PP Consult Data::Phrasebook::SQL::Query for what you can then do with your returned object. .PP For reference: the bind hashref argument, if it is given, is given to the query object's \f(CW\*(C`order_args\*(C'\fR and then \f(CW\*(C`args\*(C'\fR methods. .SH "SEE ALSO" .IX Header "SEE ALSO" Data::Phrasebook, Data::Phrasebook::Generic, Data::Phrasebook::SQL::Query. .SH "SUPPORT" .IX Header "SUPPORT" Please see the \s-1README\s0 file. .SH "AUTHOR" .IX Header "AUTHOR" .Vb 3 \& Original author: Iain Campbell Truskett (16.07.1979 \- 29.12.2003) \& Maintainer: Barbie since January 2004. \& for Miss Barbell Productions . .Ve .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" .Vb 2 \& Copyright (C) 2003 Iain Truskett. \& Copyright (C) 2004\-2013 Barbie for Miss Barbell Productions. \& \& This distribution is free software; you can redistribute it and/or \& modify it under the Artistic License v2. .Ve