Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
a55de799
Unverified
Commit
a55de799
authored
Apr 14, 2023
by
gaoyan
Committed by
GitHub
Apr 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix sql annotations replace bug (#1882)
* fix sql annotations replace bug * fix sql annotations replace bug * add testRemoveNote unit test
parent
cb1cae2b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
5 deletions
+57
-5
SqlUtilTest.java
dinky-admin/src/test/java/org/dinky/utils/SqlUtilTest.java
+49
-0
SqlUtil.java
dinky-common/src/main/java/org/dinky/utils/SqlUtil.java
+8
-5
No files found.
dinky-admin/src/test/java/org/dinky/utils/SqlUtilTest.java
0 → 100644
View file @
a55de799
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
utils
;
import
org.assertj.core.api.Assertions
;
import
org.junit.Ignore
;
import
org.junit.Test
;
/** DirUtilTest */
@Ignore
public
class
SqlUtilTest
{
@Test
public
void
testRemoveNote
()
{
String
testSql
=
"/**\n"
+
"test1\n"
+
"*/\n"
+
"//test2\n"
+
"-- test3\n"
+
"--test4\n"
+
"select 1 --test5\n"
+
" from test # test9\n"
+
" where '1' <> '-- ::.' //test6\n"
+
" and 1=1 --test7\n"
+
" and 'zz' <> null; /**test8*/"
;
String
removedNoteSql
=
SqlUtil
.
removeNote
(
testSql
);
Assertions
.
assertThat
(
removedNoteSql
).
isNotNull
();
Assertions
.
assertThat
(
removedNoteSql
).
isNotEqualTo
(
testSql
);
}
}
dinky-common/src/main/java/org/dinky/utils/SqlUtil.java
View file @
a55de799
...
...
@@ -23,6 +23,7 @@ import org.dinky.assertion.Asserts;
import
org.dinky.model.SystemConfiguration
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
/**
* SqlUtil
...
...
@@ -52,12 +53,14 @@ public class SqlUtil {
}
public
static
String
removeNote
(
String
sql
)
{
if
(
Asserts
.
isNotNullString
(
sql
))
{
sql
=
sql
.
replaceAll
(
"\u00A0"
,
" "
)
.
replaceAll
(
"[\r\n]+"
,
"\n"
)
.
replaceAll
(
"--([^'\n]{0,}('[^'\n]{0,}'){0,1}[^'\n]{0,}){0,}"
,
""
)
.
trim
();
// Remove the special-space characters
sql
=
sql
.
replaceAll
(
"\u00A0"
,
" "
).
replaceAll
(
"[\r\n]+"
,
"\n"
);
// Remove annotations Support '--aa' , '/**aaa*/' , '//aa' , '#aaa'
Pattern
p
=
Pattern
.
compile
(
"(?ms)('(?:''|[^'])*')|--.*?$|//.*?$|/\\*.*?\\*/|#.*?$|"
);
String
presult
=
p
.
matcher
(
sql
).
replaceAll
(
"$1"
);
return
presult
.
trim
();
}
return
sql
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment