tags:

views:

277

answers:

2

In propel there is this doUpdate function, that will return the numbers of affected rows by this query.

The question is, if there is no need to update the row ( because the set value is already the same as the field value), will those rows counted as the affected row?

Take for example, I have the following table:

ID | Name  | Books
1  | S1oon | Me
2  | S1oon | Me

Let's assume that I write a ORM function of the equivalent of the following query:

update `new table` set
Books='Me'
where Name='S1oon';

What will the doUpdate result return? Will it return 0 ( because all the Books column are already Me, hence there is no need to update), or will it be 2 ( because there are 2 rows that fulfill the where condition) ?

A: 

It will return 2.

Lasse V. Karlsen
+1  A: 

Under the hood, Propel is using PDO's PDOStatement::rowCount() method to return the number of affected rows. So, the short answer is that you'll get "2" as you expect here, but the longer answer is that it may depend slightly on how PDO implements that function for your specific database. (I think if you did not get 2, it should be a bug for PDO, however.)

See the description of rowCount() in the PHP manual for more info.

One other thing to bear in mind is that when Propel calls methods (like save() or delete()) which are expected to return number-of-rows-modified and which may result in more than one row being modified (e.g. if you add a Book and its Author and then cause both to be INSERTed by calling book->save()), you will get the total number of rows modified.

Hans L