I have been reading through Multiple data sets in MySQL stored procedures and am seeking clarification of exactly what is going on.

The example uses a loop whilst $sth->more_results. This suggests a situation where the number of result sets is unknown. The procedure that I have in mind would return a fixed number of result sets so I was wondering if I could simplify to this (assumes three result sets returned):

my $sth=prepare->('call my_sp($some_number);'); $sth->execute(); my $foo=$sth->fetchall_arrayref(); my $bar=$sth->fetchall_arrayref(); my $baz=$sth->fetchall_arrayref();

...or whether I have got the wrong end of the stick entirely.

Update

Having played around a bit, I have found that that $sth->more_results() must be called before the next result set appears so the code above does not work. This works:

my $sth=prepare->('call my_sp($some_number);'); $sth->execute(); my $foo=$sth->fetchall_arrayref(); $sth->more_results(); my $bar=$sth->fetchall_arrayref(); $sth->more_results(); my $baz=$sth->fetchall_arrayref();

I don't have time to write up a full example at present but can summarise that the only difference between retrieving multiple results sets is that you have to call $sth->more_results() between them.

There is now a node as a response to the original providing a cross-reference to this one.


In reply to Clarification required: multiple data sets from MySQL stored procedure by smiffy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.