2
回答
Sharding-Sphere支持case then语句吗?

UPDATE t_table_name SET isGetProduct = 1,confirmDeliveryTime =          
CASE  when subOrderId = '170406001113200002301' then now()  when subOrderId = '170406001113200002302' then now() END          
WHERE orderId = '1704060011132000023' AND areaId = 101 AND subOrderId IN  ( '170406001113200002301'  ,   '170406001113200002302')

 

这种支持吗?

<无标签>
举报
clark-lee
发帖于3个月前 2回/20阅
<update id="updateBatchConfirm">
    UPDATE t_trade_order_item_user SET isGetProduct=1,
    <trim prefix="confirmDeliveryTime =((CASE subOrderId" suffix="END))">
        <foreach collection="itemList" item="item">
            WHEN #{item.subOrderId} THEN #{item.confirmDeliveryTime}
        </foreach>
    </trim>
    WHERE userId IN
    <foreach item="item" collection="itemList" separator="," open="(" close=")">
        #{item.userId}
    </foreach>
    AND subOrderId IN
    <foreach collection="itemList" item="item" open="(" separator="," close=")">
        #{item.subOrderId}
    </foreach>
</update>

研究源码发现可这样弄,set filed_name = ((CASE id when ? then ?  when ? then ? END))   可加两个括号,就支持了, 笑哭。

 

我还尝试了多个update语句,但sharding-sphere只会给第一个update的表名进行路由,之后的update的表名不能路由,是逻辑表... 仅分库的话是支持多个update语句的

@RequiredArgsConstructor
public abstract class AbstractUpdateParser implements SQLParser {
    
    private final ShardingRule shardingRule;
    
    private final LexerEngine lexerEngine;
    
    private final AbstractUpdateClauseParserFacade updateClauseParserFacade;

    @Override
    public DMLStatement parse() {
        lexerEngine.nextToken();
        lexerEngine.skipAll(getSkippedKeywordsBetweenUpdateAndTable());
        lexerEngine.unsupportedIfEqual(getUnsupportedKeywordsBetweenUpdateAndTable());
        DMLStatement result = new DMLStatement();
        updateClauseParserFacade.getTableReferencesClauseParser().parse(result, true); // table
        updateClauseParserFacade.getUpdateSetItemsClauseParser().parse(result); // set
        lexerEngine.skipUntil(DefaultKeyword.WHERE);
        updateClauseParserFacade.getWhereClauseParser().parse(shardingRule, result, Collections.<SelectItem>emptyList()); // where
        return result;
    }
}

update的解析主要就在这里....

顶部