1DBIx::ContextualFetch(3U)ser Contributed Perl DocumentatiDoBnIx::ContextualFetch(3)
2
3
4
6 DBIx::ContextualFetch - Add contextual fetches to DBI
7
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
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
32 various fetch methods to fix this oversight. It also adds a few new
33 methods for convenience (though not necessarily efficiency).
34
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
40 normall call DBI->connect() you either call it on
41 DBIx::ContextualFetch, or that you pass this as your RootClass. After
42 this DBI will Do The Right Thing and pass all its calls through us.
43
45 execute
46 $rv = $sth->execute;
47 $rv = $sth->execute(@bind_values);
48 $rv = $sth->execute(\@bind_values, \@bind_cols);
49
50 execute() is enhanced slightly:
51
52 If called with no arguments, or with a simple list, execute() operates
53 normally. When when called with two array references, it performs the
54 functions of bind_param, execute and bind_columns similar to the
55 following:
56
57 $sth->execute(@bind_values);
58 $sth->bind_columns(undef, @bind_cols);
59
60 In addition, execute will accept tainted @bind_values. I can't think
61 of what a malicious user could do with a tainted bind value (in the
62 general case. Your application may vary.)
63
64 Thus a typical idiom would be:
65
66 $sth->execute([$this, $that], [\($foo, $bar)]);
67
68 Of course, this method provides no way of passing bind attributes
69 through to bind_param or bind_columns. If that is necessary, then you
70 must perform the bind_param, execute, bind_col sequence yourself.
71
72 fetch
73 $row_ref = $sth->fetch;
74 @row = $sth->fetch;
75
76 A context sensitive version of fetch(). When in scalar context, it will
77 act as fetchrow_arrayref. In list context it will use fetchrow_array.
78
79 fetch_hash
80 $row_ref = $sth->fetch_hash;
81 %row = $sth->fetch_hash;
82
83 A modification on fetchrow_hashref. When in scalar context, it acts
84 just as fetchrow_hashref() does. In list context it returns the
85 complete hash.
86
87 fetchall
88 $rows_ref = $sth->fetchall;
89 @rows = $sth->fetchall;
90
91 A modification on fetchall_arrayref. In scalar context it acts as
92 fetchall_arrayref. In list it returns an array of references to rows
93 fetched.
94
95 fetchall_hash
96 $rows_ref = $sth->fetchall_hash;
97 @rows = $sth->fetchall_hash;
98
99 A mating of fetchall_arrayref() with fetchrow_hashref(). It gets all
100 rows from the hash, each as hash references. In scalar context it
101 returns a reference to an array of hash references. In list context it
102 returns a list of hash references.
103
105 Michael G Schwern as part of Ima::DBI
106
108 Tony Bowden <tony@tmtm.com>
109
111 This library is free software; you can redistribute it and/or modify it
112 under the same terms as Perl itself.
113
115 DBI. Ima::DBI. Class::DBI.
116
117
118
119perl v5.34.0 2022-01-21 DBIx::ContextualFetch(3)