|
By default when using interface mapper methods with return type int returns number of rows affected.
Is there any chance to return number of rows changed (in case of insert/update)?
|
|
Hello Alex, rows affected is equal to rows changed. Libor Dne čtvrtek, 5. dubna 2012 20:44:14 UTC+2 Alex Vasilenko napsal(a): By default when using interface mapper methods with return type int returns number of rows affected. |
|
Hello Libor,
Not for me. I have MySQL connector/j as jdbc driver. I've got such a common query, like <update id="update" parameterType="com.onyx.data.photo.Photo"> UPDATE photos SET id = #{id} WHERE id = #{id} </update> Methods returns 1, when obviously nothing has changed and in fact changed rows are 0. As an example here's output for query in mysql client 127.0.0.1: (root@localhost) [baikal]>update photos set id = 1 where id = 1; Query OK, 0 rows affected (0.01 sec) Rows matched: 1 Changed: 0 Warnings: 0 Maybe tuning MySQL driver could help? Alex
On Friday, April 6, 2012 10:07:32 AM UTC+3, Libor Jelínek wrote:
|
|
It's just returning what driver returns. If the driver says it updated
one record, that's the response you'll get. Try that statement with straight JDBC, you'll get the same response. If you need to know how many records were *changed* (not that same as the number matching the where) then you might consider a stored procedure. Larry On Fri, Apr 6, 2012 at 3:10 PM, Alex Vasilenko <[hidden email]> wrote: > Hello Libor, > > Not for me. I have MySQL connector/j as jdbc driver. I've got such a common > query, like > <update id="update" parameterType="com.onyx.data.photo.Photo"> > UPDATE photos SET id = #{id} WHERE id = #{id} > </update> > > Methods returns 1, when obviously nothing has changed and in fact changed > rows are 0. As an example here's output for query in mysql client > 127.0.0.1: (root@localhost) [baikal]>update photos set id = 1 where id = 1; > Query OK, 0 rows affected (0.01 sec) > Rows matched: 1 Changed: 0 Warnings: 0 > > Maybe tuning MySQL driver could help? > > Thanks in advance, > Alex > > On Friday, April 6, 2012 10:07:32 AM UTC+3, Libor Jelínek wrote: >> >> Hello Alex, >> rows affected is equal to rows changed. >> >> Libor >> >> Dne čtvrtek, 5. dubna 2012 20:44:14 UTC+2 Alex Vasilenko napsal(a): >>> >>> By default when using interface mapper methods with return type int >>> returns number of rows affected. >>> Is there any chance to return number of rows changed (in case of >>> insert/update)? |
|
Understood. Thanks, Larry
On Saturday, April 7, 2012 12:13:45 AM UTC+3, Larry Meadors wrote: It's just returning what driver returns. If the driver says it updated |
|
Found MySQL specific workaround. If someone is curious - useAffectedRows option for jdbc url, e.g.
jdbc:mysql://${jdbc.host}/${jdbc.db}?useAffectedRows=true as found at Connector/J doc
On Wednesday, April 11, 2012 5:35:55 PM UTC+3, Alex Vasilenko wrote: Understood. Thanks, Larry |
| Powered by Nabble | Edit this page |
