scala icon indicating copy to clipboard operation
scala copied to clipboard

Dynamic SQL: choose/when/otherwise only valid in a single line

Open erysavy opened this issue 11 years ago • 8 comments

When including a conditional expression to create dynamic SQL using "choose" and enclosed "when" and "otherwise" tags, a Scala MatchError is thrown if there is any whitespace between the tags. E.g. this works ok:

<choose><when test="sometest">xx</when><otherwise>yy</otherwise></choose>

but this doesn't and throws a MatchError in line 74 of DynamicSQLBuilder.scala:

<choose>
   <when test="sometest">xx</when>
   <otherwise>yy</otherwise>
</choose>

erysavy avatar Jan 12 '14 02:01 erysavy

Hi Erysavy,

Sounds like an already fixed bug. What version of mybatis-scala are you using?

Frank.

On Sat, Jan 11, 2014 at 9:44 PM, erysavy [email protected] wrote:

When including a conditional expression to create dynamic SQL using "choose" and enclosed "when" and "otherwise" tags, a Scala MatchError is thrown if there is any whitespace between the tags. E.g. this works ok:

xxyy

but this doesn't and throws a MatchError in line 74 of DynamicSQLBuilder.scala:

xx yy

— Reply to this email directly or view it on GitHubhttps://github.com/mybatis/scala/issues/4 .

Frank D. Martínez M.

mnesarco avatar Jan 12 '14 12:01 mnesarco

Hi Frank,

I'm using the latest version in the maven repository: mybatis-scala-core_2.10 version 1.0.1.

I have checked this source version on code.google.com (trunk revision 5726): http://code.google.com/p/mybatis/source/browse/sub-projects/scala/trunk/mybatis-scala-core/src/main/scala/org/mybatis/scala/config/DynamicSQLBuilder.scala?r=5726#70 (lines 73 ... 87), there seems to be the same problem as far as I understand the code: in the loop inside the "choose" case only "when" and "otherwise" are matched, but no Atom like in the outer match block, therefore if there's any whitespace between e.g. the choose tag and the following when tag, there's no matching case block.

Regards, Eduard.

Am Sonntag, 12. Januar 2014, 04:57:23 schrieb Frank David Martínez M:

Hi Erysavy,

Sounds like an already fixed bug. What version of mybatis-scala are you using?

Frank.

On Sat, Jan 11, 2014 at 9:44 PM, erysavy [email protected] wrote:

When including a conditional expression to create dynamic SQL using "choose" and enclosed "when" and "otherwise" tags, a Scala MatchError is thrown if there is any whitespace between the tags. E.g. this works ok:

xxyy

but this doesn't and throws a MatchError in line 74 of DynamicSQLBuilder.scala:

xx yy

— Reply to this email directly or view it on GitHubhttps://github.com/mybatis/scala/issues/4 .

erysavy avatar Jan 12 '14 15:01 erysavy

Hi Eyal,

If you are using google code version, you are with an old version. We moved the code to github more than a year ago. Can you try the github version please?

https://github.com/mybatis/scala

Cheers,

Frank.

On Sun, Jan 12, 2014 at 10:11 AM, erysavy [email protected] wrote:

Hi Frank,

I'm using the latest version in the maven repository: mybatis-scala-core_2.10 version 1.0.1.

I have checked this source version on code.google.com (trunk revision 5726), there seems to be the same problem as far as I understand the code: in the loop inside the "choose" case only "when" and "otherwise" are matched, but no Atom like in the outer match block, therefore if there's any whitespace between e.g. the choose tag and the following when tag, there's no matching case block.

Regards, Eduard.

Am Sonntag, 12. Januar 2014, 04:57:23 schrieb Frank David Martínez M:

Hi Erysavy,

Sounds like an already fixed bug. What version of mybatis-scala are you using?

Frank.

On Sat, Jan 11, 2014 at 9:44 PM, erysavy [email protected] wrote:

When including a conditional expression to create dynamic SQL using "choose" and enclosed "when" and "otherwise" tags, a Scala MatchError is thrown if there is any whitespace between the tags. E.g. this works ok:

xxyy

but this doesn't and throws a MatchError in line 74 of DynamicSQLBuilder.scala:

xx yy

— Reply to this email directly or view it on GitHubhttps://github.com/mybatis/scala/issues/4 .

— Reply to this email directly or view it on GitHubhttps://github.com/mybatis/scala/issues/4#issuecomment-32124573 .

Frank D. Martínez M.

mnesarco avatar Jan 12 '14 16:01 mnesarco

Hi Erysavy,

I have confused your name (I am so sorry).

The problem was fixed two months ago in github.

https://github.com/mybatis/scala/commit/9f61f8884d7fb8343179da6a332633ea03218978#diff-15fce1edb26e4a4e020f124daeac7f7c

Can you try the unreleased github version?

Cheers,

Frank.

On Sun, Jan 12, 2014 at 11:19 AM, Frank Martínez [email protected] wrote:

Hi Eyal,

If you are using google code version, you are with an old version. We moved the code to github more than a year ago. Can you try the github version please?

https://github.com/mybatis/scala

Cheers,

Frank.

On Sun, Jan 12, 2014 at 10:11 AM, erysavy [email protected]:

Hi Frank,

I'm using the latest version in the maven repository: mybatis-scala-core_2.10 version 1.0.1.

I have checked this source version on code.google.com (trunk revision 5726), there seems to be the same problem as far as I understand the code: in the loop inside the "choose" case only "when" and "otherwise" are matched, but no Atom like in the outer match block, therefore if there's any whitespace between e.g. the choose tag and the following when tag, there's no matching case block.

Regards, Eduard.

Am Sonntag, 12. Januar 2014, 04:57:23 schrieb Frank David Martínez M:

Hi Erysavy,

Sounds like an already fixed bug. What version of mybatis-scala are you using?

Frank.

On Sat, Jan 11, 2014 at 9:44 PM, erysavy [email protected] wrote:

When including a conditional expression to create dynamic SQL using "choose" and enclosed "when" and "otherwise" tags, a Scala MatchError is thrown if there is any whitespace between the tags. E.g. this works ok:

xxyy

but this doesn't and throws a MatchError in line 74 of DynamicSQLBuilder.scala:

xx yy

— Reply to this email directly or view it on GitHubhttps://github.com/mybatis/scala/issues/4 .

— Reply to this email directly or view it on GitHubhttps://github.com/mybatis/scala/issues/4#issuecomment-32124573 .

Frank D. Martínez M.

Frank D. Martínez M.

mnesarco avatar Jan 12 '14 16:01 mnesarco

Hi Frank,

thanks for the hint and sorry for missing this before. I have tried the github version, works as expected :+1:

There's one point with this code, though: it accepts and discards any characters, even XML tags, inside the <choose> element and outside of <when> and <otherwise>. This seems a bit too permissive to me. Now that we're already talking about it, do you consider it nit-picky suggesting to restrict this to XML whitespace (which consists of either of four characters: http://www.w3.org/TR/xml/#NT-S) and throw an error for everything else?

Best, Eduard.

erysavy avatar Jan 13 '14 00:01 erysavy

Hi Erysavy,

You are right, it was a quick fix and it is too permissive. I will fix in the next release, the 1.0.2 is scheduled for today and I don't have time to review it before. So it will be fixed in 1.0.3.

Cheers,

Frank.

On Sun, Jan 12, 2014 at 7:40 PM, erysavy [email protected] wrote:

Hi Frank,

thanks for the hint and sorry for missing this before. I have tried the github version, works as expected [image: :+1:]

There's one point with this code, though: it accepts any characters, even XML tags, inside the element and outside of and . This seems a bit too permissive to me. Now that we're already talking about it, do you consider it nit-picky suggesting to restrict this to XML whitespace (which consists of either of four characters: http://www.w3.org/TR/xml/#NT-S)?

Best, Eduard.

— Reply to this email directly or view it on GitHubhttps://github.com/mybatis/scala/issues/4#issuecomment-32139577 .

Frank D. Martínez M.

mnesarco avatar Jan 15 '14 16:01 mnesarco

@mnesarco Has this issue been addressed?

hazendaz avatar Sep 12 '15 19:09 hazendaz

Hi Jeremy,

This is not addressed yet. But it is not critical and not blocking. I think it can be easily fixed, but I can't do it right now.

I hope I will have some spare time soon.

On Sat, Sep 12, 2015 at 2:33 PM, Jeremy Landis [email protected] wrote:

@mnesarco https://github.com/mnesarco Has this issue been addressed?

— Reply to this email directly or view it on GitHub https://github.com/mybatis/scala/issues/4#issuecomment-139811775.

Frank D. Martínez M.

mnesarco avatar Sep 13 '15 02:09 mnesarco