12 messages in com.mysql.lists.perlRe: BUG: $sth->rows broken for updates| From | Sent On | Attachments |
|---|---|---|
| Gregory C. Falck | 27 Aug 1999 09:21 | |
| Jochen Wiedmann | 27 Aug 1999 11:35 | |
| Gregory C. Falck | 27 Aug 1999 16:44 | |
| Eric Siegerman | 27 Aug 1999 21:11 | |
| Michael Widenius | 28 Aug 1999 02:30 | |
| Michael Widenius | 28 Aug 1999 02:39 | |
| Jochen Wiedmann | 28 Aug 1999 09:49 | |
| Jochen Wiedmann | 28 Aug 1999 09:57 | |
| Jochen Wiedmann | 29 Aug 1999 02:40 | |
| Jochen Wiedmann | 29 Aug 1999 02:40 | |
| Michael Widenius | 29 Aug 1999 11:04 | |
| Jochen Wiedmann | 29 Aug 1999 11:25 |
| Subject: | Re: BUG: $sth->rows broken for updates![]() |
|---|---|
| From: | Gregory C. Falck (greg...@lmco.com) |
| Date: | 08/27/1999 04:44:26 PM |
| List: | com.mysql.lists.perl |
First, thanks for making the software change so quick... I do appreciate it.
Just to follow up on the bug/feature issue (which you probably didn't want to hear anyway...) :)
I'll point out the following:
1. The MySQL Reference Manual at "http://www.mysql.com/Manual_chapter/manual_Clients.html#mysql_affected_rows", under mysql_affected_rows(), Return values states:
An integer greater than zero indicates the number of rows affected or retrieved.
Zero indicates that no records matched the WHERE clause in
the query or that no query has yet been executed.
In my case, I got 0 even though 1 record matched the WHERE clause. If the mysql API call is returning 0, this is a bug in either the documentation of Mysql or in the function call.
When I read the documentation, it says what I want. If the call returns the "number of records changed on disk" instead, this is interesting technically that the file writes were optimized for efficiency but is not intuitive and not of much practical use. If I have an application that updates employee records and the manager says to update all 100 employees. I don't want to report back that I updated 93 or 95 or who knows what. I want to say I updated all 100.
2. My recomendation in the context of DBI would be to make the default for $sth->rows return the true affected rows as you have done with the compile options and provide an alternate "Mysql" specific way of getting the "changed disk records".
Based on the little bit I've read from Tim Bunce, I believe this is in line with the way he thinks $sth->rows should work.
Not only that but it would make mysql based DBI programs more compatible with other DBD implementations such as Oracle, Ingres, DB2, etc.
Let the other, "I believe minority" users that need changed rather than affected, compile with the special flag.
My 0.02. Again, thanks for making the change.
Greg
Jochen Wiedmann wrote:
[CC'ed to Tim in order to terminate an old thread :-)]
"Gregory C. Falck" wrote:
Updates that change a value to to the same thing come back as 0 rows updated:
For example: object.object_title in the database is initially blank.
$stmt = q{update object set object_title='test' where object_id=162}; $sth = $dbh->prepare($stmt); $rv = $sth->execute; $rv returns 1, $sth->rows returns 1, this is correct execute it again $rv = $sth->execute; $rv returns 0E0, $sth->rows returns 0, this is wrong. The number of affected rows by the update is still 1 even though the value updated didn't change.
I'm using mysql 1.2200.
Hmmm, I forgot about this outstanding issue. This is a known behaviour of the MySQL engine, call it a bug or a feature, as you like. (It declares "affected" as "changed".) The behaviour you are expecting can be enabled by setting the C flag CLIENT_FOUND_ROWS when connecting to the database.
I have now uploaded a version 1.2205 of the Msql-Mysql-modules to CPAN which has the following new feature: When connecting with
DBI->connect("DBI:mysql:test;mysql_client_found_rows=0", ...)
then you have the old behaviour. With
DBI->connect("DBI:mysql:test;mysql_client_found_rows=1", ...)
you have CLIENT_FOUND_ROWS set, thus your query will always return 1.
The default is 0, however you can change this by compiling the Msql-Mysql-modules with
perl Makefile.PL --config --mysql-use-client-found-rows
in which case the default is 1.
Monty, I dislike that this must be choosen while connecting to the client. Couldn't we make this part of the MYSQL structure?
Thanks,
Jochen
-- Jochen Wiedmann jo...@ispsoft.de Life has brown and green eyes. :-) +49 7123 14887
--
_____________________________________________________________________ Gregory C. Falck Lockheed Martin, Enterprise Information Systems P.O. Box 4840, Electronics Parkway, E5-340, Syracuse, NY 13221-4840 Tel: (315)456-6278 Fax: (315)456-0186 E-mail: greg...@lmco.com
_____________________________________________________________________




