{
    "mode": "perldoc",
    "parameter": "DBIx::ContextualFetch",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/DBIx%3A%3AContextualFetch/json",
    "generated": "2026-06-12T23:43:50Z",
    "synopsis": "my $dbh = DBI->connect(...., { RootClass => \"DBIx::ContextualFetch\" });\n# Modified statement handle methods.\nmy $rv = $sth->execute;\nmy $rv = $sth->execute(@bindvalues);\nmy $rv = $sth->execute(\\@bindvalues, \\@bindcols);\n# In addition to the normal DBI sth methods...\nmy $rowref = $sth->fetch;\nmy @row     = $sth->fetch;\nmy $rowref = $sth->fetchhash;\nmy %row     = $sth->fetchhash;\nmy $rowsref = $sth->fetchall;\nmy @rows     = $sth->fetchall;\nmy $rowsref = $sth->fetchallhash;\nmy @tbl      = $sth->fetchallhash;",
    "sections": {
        "NAME": {
            "content": "DBIx::ContextualFetch - Add contextual fetches to DBI\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "my $dbh = DBI->connect(...., { RootClass => \"DBIx::ContextualFetch\" });\n\n# Modified statement handle methods.\nmy $rv = $sth->execute;\nmy $rv = $sth->execute(@bindvalues);\nmy $rv = $sth->execute(\\@bindvalues, \\@bindcols);\n\n# In addition to the normal DBI sth methods...\nmy $rowref = $sth->fetch;\nmy @row     = $sth->fetch;\n\nmy $rowref = $sth->fetchhash;\nmy %row     = $sth->fetchhash;\n\nmy $rowsref = $sth->fetchall;\nmy @rows     = $sth->fetchall;\n\nmy $rowsref = $sth->fetchallhash;\nmy @tbl      = $sth->fetchallhash;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "It always struck me odd that DBI didn't take much advantage of Perl's context sensitivity.\nDBIx::ContextualFetch redefines some of the various fetch methods to fix this oversight. It also\nadds a few new methods for convenience (though not necessarily efficiency).\n",
            "subsections": []
        },
        "SET-UP": {
            "content": "my $dbh = DBIx::ContextualFetch->connect(@info);\nmy $dbh = DBI->connect(@info, { RootClass => \"DBIx::ContextualFetch\" });\n\nTo use this method, you can either make sure that everywhere you normall call DBI->connect() you\neither call it on DBIx::ContextualFetch, or that you pass this as your RootClass. After this DBI\nwill Do The Right Thing and pass all its calls through us.\n",
            "subsections": []
        },
        "EXTENSIONS": {
            "content": "execute\n$rv = $sth->execute;\n$rv = $sth->execute(@bindvalues);\n$rv = $sth->execute(\\@bindvalues, \\@bindcols);\n",
            "subsections": [
                {
                    "name": "execute",
                    "content": "If called with no arguments, or with a simple list, execute() operates normally. When when\ncalled with two array references, it performs the functions of bindparam, execute and\nbindcolumns similar to the following:\n\n$sth->execute(@bindvalues);\n$sth->bindcolumns(undef, @bindcols);\n\nIn addition, execute will accept tainted @bindvalues. I can't think of what a malicious user\ncould do with a tainted bind value (in the general case. Your application may vary.)\n\nThus a typical idiom would be:\n\n$sth->execute([$this, $that], [\\($foo, $bar)]);\n\nOf course, this method provides no way of passing bind attributes through to bindparam or\nbindcolumns. If that is necessary, then you must perform the bindparam, execute, bindcol\nsequence yourself.\n\nfetch\n$rowref = $sth->fetch;\n@row     = $sth->fetch;\n\nA context sensitive version of fetch(). When in scalar context, it will act as\nfetchrowarrayref. In list context it will use fetchrowarray.\n\nfetchhash\n$rowref = $sth->fetchhash;\n%row     = $sth->fetchhash;\n\nA modification on fetchrowhashref. When in scalar context, it acts just as fetchrowhashref()\ndoes. In list context it returns the complete hash.\n\nfetchall\n$rowsref = $sth->fetchall;\n@rows     = $sth->fetchall;\n\nA modification on fetchallarrayref. In scalar context it acts as fetchallarrayref. In list it\nreturns an array of references to rows fetched.\n\nfetchallhash\n$rowsref = $sth->fetchallhash;\n@rows     = $sth->fetchallhash;\n\nA mating of fetchallarrayref() with fetchrowhashref(). It gets all rows from the hash, each as\nhash references. In scalar context it returns a reference to an array of hash references. In\nlist context it returns a list of hash references.\n"
                }
            ]
        },
        "ORIGINAL AUTHOR": {
            "content": "Michael G Schwern as part of Ima::DBI\n",
            "subsections": []
        },
        "CURRENT MAINTAINER": {
            "content": "Tony Bowden <tony@tmtm.com>\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "DBI. Ima::DBI. Class::DBI.\n",
            "subsections": []
        }
    },
    "summary": "DBIx::ContextualFetch - Add contextual fetches to DBI",
    "flags": [],
    "examples": [],
    "see_also": []
}