DBIx::C...ualFetch(3)
πΈ DBIx::ContextualFetch(3) πΈ
okay bestie, welcome to the User Contributed Perl Documentation page for DBIx::ContextualFetch β yes, the manual name is right there, and it is literally giving βletβs make DBI context-sensitiveβ energy β¨
π NAME π
DBIx::ContextualFetch β Add contextual fetches to DBI. No cap.
β¨ SYNOPSIS β¨
my $dbh = DBI->connect(...., { RootClass => "DBIx::ContextualFetch" });
# Modified statement handle methods.
my $rv = $sth->execute;
my $rv = $sth->execute(@bind_values);
my $rv = $sth->execute(\@bind_values, \@bind_cols);
# In addition to the normal DBI sth methods...
my $row_ref = $sth->fetch;
my @row = $sth->fetch;
my $row_ref = $sth->fetch_hash;
my %row = $sth->fetch_hash;
my $rows_ref = $sth->fetchall;
my @rows = $sth->fetchall;
my $rows_ref = $sth->fetchall_hash;
my @tbl = $sth->fetchall_hash;
π¦ DESCRIPTION π¦
okay so it lowkey always struck me as odd that DBI didnβt take much advantage of Perlβs context sensitivity. DBIx::ContextualFetch redefines some of the various fetch methods to fix this oversight. It also adds a few new methods for convenience (though not necessarily efficiency). π«Ά
π SET-UP π
my $dbh = DBIx::ContextualFetch->connect(@info);
my $dbh = DBI->connect(@info, { RootClass => "DBIx::ContextualFetch" });
To use this method, you can either make sure that everywhere you normall call DBI->connect() you either call it on DBIx::ContextualFetch, or that you pass this as your RootClass. After this DBI will Do The Right Thing and pass all its calls through us. π
π οΈ EXTENSIONS π οΈ
β‘ execute β‘
$rv = $sth->execute;
$rv = $sth->execute(@bind_values);
$rv = $sth->execute(\@bind_values, \@bind_cols);
execute() is enhanced slightly:
If called with no arguments, or with a simple list, execute() operates normally. When when called with two array references, it performs the functions of bind_param, execute and bind_columns similar to the following:
$sth->execute(@bind_values);
$sth->bind_columns(undef, @bind_cols);
In addition, execute will accept tainted @bind_values. I canβt think of what a malicious user could do with a tainted bind value (in the general case. Your application may vary.) π
Thus a typical idiom would be:
$sth->execute([$this, $that], [\($foo, $bar)]);
β οΈ Of course, this method provides no way of passing bind attributes through tobind_paramorbind_columns. If that is necessary, then you must perform thebind_param,execute,bind_colsequence yourself. periodt.
π₯ fetch π₯
$row_ref = $sth->fetch;
@row = $sth->fetch;
A context sensitive version of fetch(). When in scalar context, it will act as fetchrow_arrayref. In list context it will use fetchrow_array. π
π fetch_hash π
$row_ref = $sth->fetch_hash;
%row = $sth->fetch_hash;
A modification on fetchrow_hashref. When in scalar context, it acts just as fetchrow_hashref() does. In list context it returns the complete hash. π
π fetchall π
$rows_ref = $sth->fetchall;
@rows = $sth->fetchall;
A modification on fetchall_arrayref. In scalar context it acts as fetchall_arrayref. In list it returns an array of references to rows fetched. π¦
π fetchall_hash π
$rows_ref = $sth->fetchall_hash;
@rows = $sth->fetchall_hash;
A mating of fetchall_arrayref() with fetchrow_hashref(). It gets all rows from the hash, each as hash references. In scalar context it returns a reference to an array of hash references. In list context it returns a list of hash references. π
π«Ά ORIGINAL AUTHOR π«Ά
Michael G Schwern as part of Ima::DBI πΈ
π CURRENT MAINTAINER π
Tony Bowden <tony@tmtm.com> π«Ά
π LICENSE π
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
π SEE ALSO π
DBI. Ima::DBI. Class::DBI. π§
mwah π okay bye bestie β this page is from perl v5.42.0, dated 2011-04-08, and its footer name is DBIx::C...ualFetch(3). π
π¦ where this page comes from
- opensuse-leap 16.0: perl-DBIx-ContextualFetch 1.03-bp160.1.11 Β· GPL-1.0+ or Artistic-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms