1DBIx::ContextualFetch(3U)ser Contributed Perl DocumentatiDoBnIx::ContextualFetch(3)
2
3
4

NAME

6       DBIx::ContextualFetch - Add contextual fetches to DBI
7

SYNOPSIS

9               my $dbh = DBI->connect(...., { RootClass => "DBIx::ContextualFetch" });
10
11               # Modified statement handle methods.
12               my $rv = $sth->execute;
13               my $rv = $sth->execute(@bind_values);
14               my $rv = $sth->execute(\@bind_values, \@bind_cols);
15
16               # In addition to the normal DBI sth methods...
17               my $row_ref = $sth->fetch;
18               my @row     = $sth->fetch;
19
20               my $row_ref = $sth->fetch_hash;
21               my %row     = $sth->fetch_hash;
22
23               my $rows_ref = $sth->fetchall;
24               my @rows     = $sth->fetchall;
25
26               my $rows_ref = $sth->fetchall_hash;
27               my @tbl      = $sth->fetchall_hash;
28

DESCRIPTION

30       It always struck me odd that DBI didn't take much advantage of Perl's
31       context sensitivity. DBIx::ContextualFetch redefines some of the vari‐
32       ous fetch methods to fix this oversight. It also adds a few new methods
33       for convenience (though not necessarily efficiency).
34

SET-UP

36               my $dbh = DBIx::ContextualFetch->connect(@info);
37               my $dbh = DBI->connect(@info, { RootClass => "DBIx::ContextualFetch" });
38
39       To use this method, you can either make sure that everywhere you nor‐
40       mall call DBI->connect() you either call it on DBIx::ContextualFetch,
41       or that you pass this as your RootClass. After this DBI will Do The
42       Right Thing and pass all its calls through us.
43

EXTENSIONS

45       execute
46
47               $rv = $sth->execute;
48               $rv = $sth->execute(@bind_values);
49               $rv = $sth->execute(\@bind_values, \@bind_cols);
50
51       execute() is enhanced slightly:
52
53       If called with no arguments, or with a simple list, execute() operates
54       normally.  When when called with two array references, it performs the
55       functions of bind_param, execute and bind_columns similar to the fol‐
56       lowing:
57
58               $sth->execute(@bind_values);
59               $sth->bind_columns(undef, @bind_cols);
60
61       In addition, execute will accept tainted @bind_values.  I can't think
62       of what a malicious user could do with a tainted bind value (in the
63       general case. Your application may vary.)
64
65       Thus a typical idiom would be:
66
67               $sth->execute([$this, $that], [\($foo, $bar)]);
68
69       Of course, this method provides no way of passing bind attributes
70       through to bind_param or bind_columns. If that is necessary, then you
71       must perform the bind_param, execute, bind_col sequence yourself.
72
73       fetch
74
75               $row_ref = $sth->fetch;
76               @row     = $sth->fetch;
77
78       A context sensitive version of fetch(). When in scalar context, it will
79       act as fetchrow_arrayref. In list context it will use fetchrow_array.
80
81       fetch_hash
82
83               $row_ref = $sth->fetch_hash;
84               %row     = $sth->fetch_hash;
85
86       A modification on fetchrow_hashref. When in scalar context, it acts
87       just as fetchrow_hashref() does. In list context it returns the com‐
88       plete hash.
89
90       fetchall
91
92               $rows_ref = $sth->fetchall;
93               @rows     = $sth->fetchall;
94
95       A modification on fetchall_arrayref. In scalar context it acts as
96       fetchall_arrayref. In list it returns an array of references to rows
97       fetched.
98
99       fetchall_hash
100
101               $rows_ref = $sth->fetchall_hash;
102               @rows     = $sth->fetchall_hash;
103
104       A mating of fetchall_arrayref() with fetchrow_hashref(). It gets all
105       rows from the hash, each as hash references. In scalar context it
106       returns a reference to an array of hash references. In list context it
107       returns a list of hash references.
108

ORIGINAL AUTHOR

110       Michael G Schwern as part of Ima::DBI
111

CURRENT MAINTAINER

113       Tony Bowden <tony@tmtm.com>
114

LICENSE

116       This library is free software; you can redistribute it and/or modify it
117       under the same terms as Perl itself.
118

SEE ALSO

120       DBI. Ima::DBI. Class::DBI.
121
122
123
124perl v5.8.8                       2005-09-27          DBIx::ContextualFetch(3)
Impressum