Is it ok to have several (more than one) UPDATE statement inside a single <UPDATE> element ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it ok to have several (more than one) UPDATE statement inside a single <UPDATE> element ?

Кирилл Марчук

I put 2 SQL UPDATE queries in a single UPDATE element (these queries should always run one after another in a single transaction)

This seems to work OK, but the Updates (number of changed rows) are displayed (with TRACE level verbosity for mapper) only for the first one.

Is this a bug or a space for improvement ? Or I would better never use mapper this way ?

thanks a lot for comments

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Is it ok to have several (more than one) UPDATE statement inside a single <UPDATE> element ?

Guy Rouillier-2
You don't mention which DBMS you are using.  But in general, to execute multiple SQL statements with a single DBMS call, you should put them into a procedure or function.  You can do this in most DBMSs inline by using an anonymous block.  Both Oracle and PostgreSQL support anonymous blocks.  As to what the return value of an anonymous block is, this is not a standardized feature, so each vendor can define the return value as they feel appropriate.

You also have the option of controlling the start and end of the transaction yourself, then just invoking multiple individual MyBatis <update> statements.  Since you are explicitly executing each SQL statement, you would then have the traditional return value (rows updated in the case of an update statement.)  Unless you have a routine need to run the statements together via an anonymous block, this approach would probably be a simpler way to go.  Theoretically, the anonymous block approach might be more efficient since the whole thing gets sent to the server in one shot.  But the JDBC driver might optimize the second approach in a similar fashion once it sees both statements running in a single transaction.

--
Guy Rouillier

------ Original Message ------
From: "Кирилл Марчук" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 11/14/2017 1:36:03 AM
Subject: Is it ok to have several (more than one) UPDATE statement inside a single <UPDATE> element ?


I put 2 SQL UPDATE queries in a single UPDATE element (these queries should always run one after another in a single transaction)

This seems to work OK, but the Updates (number of changed rows) are displayed (with TRACE level verbosity for mapper) only for the first one.

Is this a bug or a space for improvement ? Or I would better never use mapper this way ?

thanks a lot for comments

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

ttsqfac0.png (122 bytes) Download Attachment
mowzjts5.png (160 bytes) Download Attachment
hhnism3r.png (294 bytes) Download Attachment
zq0pqqvu.png (286 bytes) Download Attachment
wybnp4i4.gif (154 bytes) Download Attachment
h41lvupp.png (126 bytes) Download Attachment
2v0wypc4.png (126 bytes) Download Attachment
atdil420.gif (2K) Download Attachment
eqcfxc4l.png (298 bytes) Download Attachment
cwufxw02.png (310 bytes) Download Attachment
cxv1fci1.png (138 bytes) Download Attachment
hhxyv34c.png (138 bytes) Download Attachment
edsne2gs.png (328 bytes) Download Attachment
cw2cx3vx.png (332 bytes) Download Attachment
cde5jyc5.png (172 bytes) Download Attachment
khvrjfhd.png (168 bytes) Download Attachment
wlpg5iet.png (118 bytes) Download Attachment
w0kkqjjm.png (298 bytes) Download Attachment
5e3m0pyn.png (180 bytes) Download Attachment
cp4hsjlp.png (130 bytes) Download Attachment
a5gdnm4a.png (1K) Download Attachment
wrek3r1j.png (1K) Download Attachment
yksyvhxk.png (1K) Download Attachment
3vjpo113.png (466 bytes) Download Attachment
1ux4jelv.png (352 bytes) Download Attachment