Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

Commit 16000c6

Browse files
committed
fix #2 #3 ,update version='0.1.5'
1 parent 7d47298 commit 16000c6

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

mybatis_mapper2sql/convert.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,16 @@ def convert_trim_where_set(mybatis_mapper, child):
145145
convert_string += convert_children(mybatis_mapper, next_child)
146146
# Remove prefixOverrides
147147
if prefix_overrides:
148-
regex = '^[\s]*?' + prefix_overrides
148+
regex = fr'^[\s]*?({prefix_overrides})'
149149
convert_string = re.sub(regex, '', convert_string, count=1, flags=re.I)
150150
# Remove suffixOverrides
151151
if suffix_overrides:
152-
regex = suffix_overrides + '(\s+--.+)?$'
153-
convert_string = re.sub(regex, r'\1', convert_string, count=1, flags=re.I)
152+
regex = fr'{suffix_overrides}(\s+--.+)?$'
153+
convert_string = re.sub(regex, r'', convert_string, count=1, flags=re.I)
154154
# Add Prefix if String is not empty
155-
if re.search('\S', convert_string):
156-
convert_string = prefix + ' ' + convert_string
155+
if re.search(r'\S', convert_string):
156+
if prefix:
157+
convert_string = prefix + ' ' + convert_string
157158
if suffix:
158159
convert_string = convert_string + ' ' + suffix
159160
# Add trim/where/set tail

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def run_tests(self):
2525

2626
setup(
2727
name='mybatis-mapper2sql',
28-
version='0.1.4',
28+
version='0.1.5',
2929
author='hhyo',
3030
author_email='[email protected]',
3131
url='http://github.com/hhyo/mybatis-mapper2sql',

tests/test.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@
7878
OR price = 200
7979
</trim>
8080
</select>
81+
<select id="testTrim">
82+
SELECT
83+
name,
84+
category,
85+
price
86+
FROM
87+
fruits
88+
<trim prefix="WHERE" prefixOverrides="AND|OR">
89+
OR category = 'apple'
90+
OR price = 200
91+
</trim>
92+
AND
93+
<trim prefixOverrides="AND|OR">
94+
(type = 40 OR type= 60) and yn = 1
95+
</trim>
96+
</select>
8197
<select id="testWhere">
8298
SELECT
8399
name,

0 commit comments

Comments
 (0)