sqle icon indicating copy to clipboard operation
sqle copied to clipboard

MyBatis 解析无法进行分支判断,导致部分XML无法得到正确的SQL

Open sjjian opened this issue 3 years ago • 3 comments

SQLe Version

Describe the bug

To Reproduce

Expected behavior

Suggestion

sjjian avatar Nov 01 '22 05:11 sjjian

https://github.com/actiontech/sqle/issues/959

		order by
		<choose>
			<when test="vo.orderByClause=='transFee desc'">p.trans_fee desc </when>
			<when test="vo.orderByClause=='transFee asc'">p.trans_fee asc </when>
			<when test="vo.orderByClause=='transFeeRate desc'">p.trans_fee_rate desc </when>
			<when test="vo.orderByClause=='transFeeRate asc'">p.trans_fee_rate asc </when>
			<when test="vo.orderByClause=='priority desc'">p.priority desc</when>
			<when test="vo.orderByClause=='priority asc'">p.priority asc </when>
			<when test="vo.orderByClause=='withdrawPriority desc'">pwithdraw_priority desc </when>
			<when test="vo.orderByClause=='withdrawPriority asc'">p.withdraw_priority asc </when>
			<otherwise>p.create_time desc </otherwise>
		</choose>

sjjian avatar Nov 01 '22 05:11 sjjian

https://github.com/actiontech/sqle/issues/949 语法错误或者解析器不支持,请人工确认SQL正确性

group by cm.merchant_nogroup by cm.pay_dayorder by total_sk_count DESC,merchant_no ascorder by total_sk_amount DESC,merchant_no ascorder by total_dk_count DESC,merchant_no ascorder by total_dk_amount DESC,merchant_no ascorder by (total_dk_count+total_sk_count) DESC,merchant_no ascorder by (total_dk_amount+total_sk_amount) DESC,merchant_no ascorder by (sum(total_dk_count)+sum(total_sk_count)) desc,merchant_no ascorder by (sum(total_dk_amount)+sum(total_sk_amount)) desc,merchant_no asc;

<if test="vo.groupByClause != null and !(vo.groupByClause.indexOf(';')>=0)  and !(vo.groupByClause.indexOf('\'')>=0)">
    <if test="vo.groupByClause=='merchant_no'">group by cm.merchant_no</if>
    <if test="vo.groupByClause=='pay_day'">group by cm.pay_day</if>
</if>
<if test="vo.orderByClause != null and !(vo.orderByClause.indexOf(';')>=0)  and !(vo.orderByClause.indexOf('\'')>=0)">

  <if test="vo.orderByClause == 'total_sk_count DESC,merchant_no asc'">order by total_sk_count DESC,merchant_no asc</if>
  <if test="vo.orderByClause == 'total_sk_amount DESC,merchant_no asc'">order by total_sk_amount DESC,merchant_no asc</if>

  <if test="vo.orderByClause == 'total_dk_count DESC,merchant_no asc'">order by total_dk_count DESC,merchant_no asc</if>
  <if test="vo.orderByClause == 'total_dk_amount DESC,merchant_no asc'">order by total_dk_amount DESC,merchant_no asc</if>

  <if test="vo.orderByClause == '(total_dk_count+total_sk_count) DESC,merchant_no asc'">order by (total_dk_count+total_sk_count) DESC,merchant_no asc</if>
  <if test="vo.orderByClause == '(total_dk_amount+total_sk_amount) DESC,merchant_no asc'">order by (total_dk_amount+total_sk_amount) DESC,merchant_no asc</if>

  <if test="vo.orderByClause == '(sum(total_dk_count)+sum(total_sk_count)) desc,merchant_no asc'">order by (sum(total_dk_count)+sum(total_sk_count)) desc,merchant_no asc</if>
  <if test="vo.orderByClause == '(sum(total_dk_amount)+sum(total_sk_amount)) desc,merchant_no asc'">order by (sum(total_dk_amount)+sum(total_sk_amount)) desc,merchant_no asc</if>

</if>

sjjian avatar Nov 01 '22 05:11 sjjian

https://github.com/actiontech/sqle/issues/967 语法错误或者解析器不支持,请人工确认SQL正确性

select * from product_info where
		location_code = ?location_code='ID' 
		group by BINARY product_code
	;
	<select id="getAllDistinctProduct" resultMap="ProductInfoResultMap">
		select * from product_info where
		<choose>
			<when test="locationCode != null and locationCode != ''">location_code = #{locationCode}</when>
			<otherwise>location_code='ID' </otherwise>
		</choose>
		group by BINARY product_code
	</select>

sjjian avatar Nov 01 '22 05:11 sjjian