Remove the blank lines in XML https://github.com/mybatis/mybatis-3/issues/1126#

Comment From: harawata

String literals should not be modified.

insert into (id, desc) values (1, '----
  some text
---');

All we can do, I think, is to remove leading/trailing whitespaces (i.e. trim()).

Comment From: zhaoxi2000

@harawata OK . Let me see....

Comment From: zhaoxi2000

Update / Insert into , is the values not dynamic ? It would write in XML... I think it is not actual SQL.

Comment From: harawata

Hi @zhaoxi1988 , Users can write literals (= non-dynamic values) in mapper statements.

Comment From: zhaoxi2000

@harawata

What is your idea to handle source-sql in Mapper.xml ? Only specify the node ?

Comment From: harawata

I'll comment soon. Sorry for the delay!

Comment From: harawata

Hi @zhaoxi1988 , I forgot to write, thank you for the PR!

Quick question. If only the first and the last line breaks are removed, is it still useful?

Adding a new option is a big deal to MyBais and this feature has only limited uses, so I wanted to fix this without adding a new option. But then, we probably cannot remove most line breaks because it could break string literals in SQL.

Comment From: zhaoxi2000

@harawata It is useful when it occurs at our high concurrent application. We need the SQL in InnoDB log.

Below the question , we can fix it.

it could break string literals in SQL

Comment From: harawata

Below the question , we can fix it.

it could break string literals in SQL

Are you thinking about parsing SQL? I hope not because it's a bad idea...

We need the SQL in InnoDB log.

Yes, I think it is a reasonable request. I'm just not sure what is the best way to support this.

Comment From: zhaoxi2000

@harawata

It is not very good practice.

insert into (id, desc) values (1, '---- some text ---');

What do you think about that we only specify the <select> node ?

Comment From: harawata

@zhaoxi1988 ,

Users can write literal values in a SELECT statement, too. :(

It might be possible to write a custom language driver that removes whitespaces. As it is a user-side solution, you can ignore the tricky literal issue if you don't use it. I'll look into it once I have time.

Comment From: harawata

I'm sorry for the lack of response.

I tried to write a custom language driver, but with the current implementation, it requires a lot of copy & paste. :( I'll ask other devs if they have a good idea.

Comment From: zhaoxi2000

I'm sorry for the lack of response.

I tried to write a custom language driver, but with the current implementation, it requires a lot of copy & paste. :( I'll ask other devs if they have a good idea.

Have a good idea to construct this function?

Comment From: harbulot

Just a quick point about string literals: they're not necessarily within single quotes ('), so relying on SQL parsing would indeed cause further problems.

For example, PostgreSQL can have Dollar-quoted String Constants:

$$Dianne's horse$$
$SomeTag$Dianne's horse$SomeTag$

Comment From: harawata

Replaced by #1901