mybatis-dynamic-sql:How to implement signing "self-increment" value?

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

mybatis-dynamic-sql:How to implement signing "self-increment" value?

Bin
It said that I have a table:
CREATE TABLE `t_table` (
  `col` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

insert into t_table values (1),(2), (3);




I want to use mybatis-dynamic-sql to create a MySQL update statement  like:
   
update t_table set `col`=`col`+1;

which result to:
---------------
 | col       |
---------------
     2
----------
     3
----------
     4
----------



But I have no idea how to tranfer "set `col`=`col`+1" into code.

Any suggestion is appreciated.

--
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.
Bin
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-dynamic-sql:How to implement signing "self-increment" value?

Bin
I find the solution by myself. The code below is work.
UpdateDSL.update(TTableDynamicSqlSupport.tTable)
                .set(TTableDynamicSqlSupport.col).equalToConstant("`col` + 1")
                .build().render(RenderingStrategy.MYBATIS3);

But, the method name "equalToConstant" is so strange, isn't it?

在 2018年6月26日星期二 UTC+8下午5:43:09,Bin写道:
It said that I have a table:
CREATE TABLE `t_table` (
  `col` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

insert into t_table values (1),(2), (3);




I want to use mybatis-dynamic-sql to create a MySQL update statement  like:
   
update t_table set `col`=`col`+1;

which result to:
---------------
 | col       |
---------------
     2
----------
     3
----------
     4
----------



But I have no idea how to tranfer "set `col`=`col`+1" into code.

Any suggestion is appreciated.

--
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.
Bin
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-dynamic-sql:How to implement signing "self-increment" value?

Bin
Another solution that does not hard code the column name is show below.
UpdateDSL.update(TTableDynamicSqlSupport.tTable)
               .set(TTableDynamicSqlSupport.col).equalTo(add(col, constant("1")))
               .build().render(RenderingStrategy.MYBATIS3);


--
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.