10 messages in com.mysql.lists.perlRe: mSQL: Number of rows affected nev...| From | Sent On | Attachments |
|---|---|---|
| Paul Hoepfner-Homme | 03 Mar 2001 09:00 | |
| Jochen Wiedmann | 03 Mar 2001 11:33 | |
| Paul Hoepfner-Homme | 05 Mar 2001 07:08 | |
| Jochen Wiedmann | 05 Mar 2001 08:39 | |
| Paul Hoepfner-Homme | 05 Mar 2001 09:13 | .pl |
| Jochen Wiedmann | 06 Mar 2001 03:37 | |
| Paul Hoepfner-Homme | 06 Mar 2001 08:44 | |
| Paul Hoepfner-Homme | 06 Mar 2001 09:00 | |
| Dodger | 06 Mar 2001 11:27 | |
| Paul Hoepfner-Homme | 07 Mar 2001 09:07 |
| Subject: | Re: mSQL: Number of rows affected never correctly returned![]() |
|---|---|
| From: | Dodger (se...@aquest.com) |
| Date: | 03/06/2001 11:27:09 AM |
| List: | com.mysql.lists.perl |
----- Original Message ----- From: "Paul Hoepfner-Homme" <pmho...@student.math.uwaterloo.ca> To: "Jochen Wiedmann" <jo...@ispsoft.de> Cc: <msql...@lists.mysql.com> Sent: Tuesday, March 06, 2001 11:44 AM Subject: Re: mSQL: Number of rows affected never correctly returned
Well, I guess I can try that out to see if it works, but it would be harder to implement it this way in my particular application. Essentially it has a query console which must be able to accept any generic query, including INSERTs, SELECTs, DELETEs, UPDATEs, etc. This is why I am using the $dbh->prepare() .. $sth->execute() sequence, because it can handle any type of query. It works by counting the fields after the query has been executed, which will be at least one if it was a SELECT query. In that case it displays the rows selected by the query. Otherwise it displays the number of rows affected by calling $sth->rows.
You don't have to use do() to get this functionality...
You just cannot use rows() for the rows affected. You can, however, I'm pretty
certain, still take the return value of the execute, except in the case of
select, like so:
my $statement = $cgi->query(statement); my $query = $dbh->prepare($statement); my $raf = $query->execute; print "<pre>$statement</pre>\n"; print "<table>\n"; my $count = 0; if ($raf eq '0E0') { # that's what a SELECT gives you back while (my @row = $query->fetchrow_array) { $count = 0 if $count > 5;# this count bit # gives three lines grey, # three lines white as bgcolour. my $colour = $count > 2?"DDDDDD":"FFFFFF"; print "<tr bgcolor=\"$colour\"><td>", (join "</td><td>", @row), "</td></tr>\n"; $count++;}} elsif ($raf) { # if there's a value, # $raf rows were affected. printf "<tr><td>Done. $raf Row%s Affected.</td></tr>\n", $raf>1?'s':undef;}# I hate seeing '1 rows' else { print "<tr><td>Done. <font color=\"red\">No rows ". "were affected.</font></td></tr>\n";} # I also hate seeing '0 rows'
print "</table>\n";
-- Dodger





.pl