[prev in list] [next in list] [prev in thread] [next in thread] 

List:       msql-mysql-modules
Subject:    Re: $st->{NAME} broken after fetchall_arrayref()
From:       Adrian Phillips <adrianp () powertech ! no>
Date:       1998-10-16 4:51:04
[Download RAW message or body]

>>>>> "Renaud" == Renaud Waldura <rwaldura@ligos.com> writes:

    Renaud> Hi, After upgrading to the latest DBI & DBD::mysql, I've
    Renaud> found $st->{NAME} to be broken when used after
    Renaud> fetchall_arrayref().

    Renaud> -----------------------------------------------------------

    Renaud> 	use DBI;

    Renaud> 	$db = DBI->connect('DBI:mysql:test_tmp9');

    Renaud> 	$st = $db->prepare("select * from orders");
    Renaud> $st->execute();

    Renaud> 	if ($#ARGV) { $st->fetch(); # here } else {
    Renaud> $st->fetchall_arrayref(); # there }

    Renaud> 	$names = $st->{NAME};

    Renaud> 	print join("\n", @$names), "\n";

    Renaud> 	$st->finish();

    Renaud> 	$db->disconnect();

    Renaud> -----------------------------------------------------------

    Renaud> When using $st->fetch(), $st->{NAME} returns the column
    Renaud> names as expected.  But after using
    Renaud> $st->fetchall_arrayref(), $st->{NAME} returns an empty
    Renaud> array.  It does work if I use $st->{NAME} before any
    Renaud> fetch().

I think this was the "problem" that I had - basically when the last
row is read the DBD can mark the statement handle as finished
automatically

This section by Jochen (Wiedmann) was posted to dbi-devel some days
ago for discussion after I'd posted about my problem with the same
thing (NAME not valid after selectall_arrayref) :

	- Recommend that portable applications should not read
	  $sth->{NAME} or $sth->{TYPE} after $sth->finish() was done or
	  $sth->fetch() indicated end of data. (To be precise if
	  !$sth->{Active}.)

The solution is quiote simple - grab what you need before do running
through all the rows because as soon as you find the last you won't be
able to get at it (well, at least NAME and TYPE as mentioned above).

(Jochen, please correct me if this doesn't apply in this case)

Sincerely,

Adrian
-----------------------------------------------------------
Send a mail to mdomo@tcx.se with
unsubscribe msql-mysql-modules your@subscription.address
in the body of the message to unsubscribe from this list.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic