Skip to content

Commit 400f7e5

Browse files
authored
Merge pull request #205 from domaframework/oracle-full-width-wild-cards
Remove full-width `%` and `_` from wild cards in Oracle dialect
2 parents ff00a89 + f1649ce commit 400f7e5

File tree

3 files changed

+112
-48
lines changed

3 files changed

+112
-48
lines changed

src/main/java/org/seasar/doma/jdbc/dialect/OracleDialect.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ public static class OracleSqlLogFormattingVisitor
144144
*/
145145
public static class OracleExpressionFunctions
146146
extends Oracle11ExpressionFunctions {
147+
148+
private final static char[] DEFAULT_WILDCARDS = { '%', '_' };
149+
150+
public OracleExpressionFunctions() {
151+
super(DEFAULT_WILDCARDS);
152+
}
153+
154+
public OracleExpressionFunctions(char[] wildcards) {
155+
super(wildcards);
156+
}
157+
158+
public OracleExpressionFunctions(char escapeChar, char[] wildcards) {
159+
super(escapeChar, wildcards);
160+
}
161+
147162
}
148163

149164
/**
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2004-2010 the Seasar Foundation and the Others.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
* either express or implied. See the License for the specific language
14+
* governing permissions and limitations under the License.
15+
*/
16+
package org.seasar.doma.jdbc.dialect;
17+
18+
import java.sql.Date;
19+
import java.sql.Time;
20+
import java.sql.Timestamp;
21+
import java.text.SimpleDateFormat;
22+
23+
import org.seasar.doma.expr.ExpressionFunctions;
24+
import org.seasar.doma.internal.jdbc.sql.ConvertToLogFormatFunction;
25+
import org.seasar.doma.jdbc.SqlLogFormattingVisitor;
26+
import org.seasar.doma.wrapper.DateWrapper;
27+
import org.seasar.doma.wrapper.TimeWrapper;
28+
import org.seasar.doma.wrapper.TimestampWrapper;
29+
import org.seasar.doma.wrapper.UtilDateWrapper;
30+
31+
import junit.framework.TestCase;
32+
33+
/**
34+
* @author taedium
35+
*
36+
*/
37+
public class Oracle11DialectTest extends TestCase {
38+
39+
public void testExpressionFunctions_prefix() throws Exception {
40+
Oracle11Dialect dialect = new Oracle11Dialect();
41+
ExpressionFunctions functions = dialect.getExpressionFunctions();
42+
assertEquals("a$$a$%a$_a$%a$_%", functions.prefix("a$a%a_a%a_"));
43+
}
44+
45+
public void testExpressionFunctions_prefix_escape() throws Exception {
46+
Oracle11Dialect dialect = new Oracle11Dialect();
47+
ExpressionFunctions functions = dialect.getExpressionFunctions();
48+
assertEquals("a!!a!%a!_a!%a!_%", functions.prefix("a!a%a_a%a_", '!'));
49+
}
50+
51+
public void testExpressionFunctions_prefix_escapeWithBackslash()
52+
throws Exception {
53+
Oracle11Dialect dialect = new Oracle11Dialect();
54+
ExpressionFunctions functions = dialect.getExpressionFunctions();
55+
assertEquals("a\\\\a\\%a\\_a\\%a\\_%",
56+
functions.prefix("a\\a%a_a%a_", '\\'));
57+
}
58+
59+
public void testDateFormat() throws Exception {
60+
Oracle11Dialect dialect = new Oracle11Dialect();
61+
SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
62+
DateWrapper wrapper = new DateWrapper(Date.valueOf("2009-01-23"));
63+
assertEquals("date'2009-01-23'", wrapper.accept(visitor,
64+
new ConvertToLogFormatFunction(), null));
65+
}
66+
67+
public void testTimeFormat() throws Exception {
68+
Oracle11Dialect dialect = new Oracle11Dialect();
69+
SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
70+
TimeWrapper wrapper = new TimeWrapper(Time.valueOf("01:23:45"));
71+
assertEquals("time'01:23:45'", wrapper.accept(visitor,
72+
new ConvertToLogFormatFunction(), null));
73+
}
74+
75+
public void testTimestampFormat() throws Exception {
76+
Oracle11Dialect dialect = new Oracle11Dialect();
77+
SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
78+
TimestampWrapper wrapper = new TimestampWrapper(
79+
Timestamp.valueOf("2009-01-23 01:23:45.123456789"));
80+
assertEquals("timestamp'2009-01-23 01:23:45.123456789'", wrapper
81+
.accept(visitor, new ConvertToLogFormatFunction(), null));
82+
}
83+
84+
public void testUtilDateFormat() throws Exception {
85+
Oracle11Dialect dialect = new Oracle11Dialect();
86+
SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
87+
UtilDateWrapper wrapper = new UtilDateWrapper(
88+
new SimpleDateFormat("yyyy-MM-dd HH:mm:sss.SSS")
89+
.parse("2009-01-23 12:34:56.789"));
90+
assertEquals("timestamp'2009-01-23 12:34:56.789'", wrapper
91+
.accept(visitor, new ConvertToLogFormatFunction(), null));
92+
}
93+
}

src/test/java/org/seasar/doma/jdbc/dialect/OracleDialectTest.java

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,10 @@
1515
*/
1616
package org.seasar.doma.jdbc.dialect;
1717

18-
import java.sql.Date;
19-
import java.sql.Time;
20-
import java.sql.Timestamp;
21-
import java.text.SimpleDateFormat;
18+
import org.seasar.doma.expr.ExpressionFunctions;
2219

2320
import junit.framework.TestCase;
2421

25-
import org.seasar.doma.expr.ExpressionFunctions;
26-
import org.seasar.doma.internal.jdbc.sql.ConvertToLogFormatFunction;
27-
import org.seasar.doma.jdbc.SqlLogFormattingVisitor;
28-
import org.seasar.doma.wrapper.DateWrapper;
29-
import org.seasar.doma.wrapper.TimeWrapper;
30-
import org.seasar.doma.wrapper.TimestampWrapper;
31-
import org.seasar.doma.wrapper.UtilDateWrapper;
32-
3322
/**
3423
* @author taedium
3524
*
@@ -39,54 +28,21 @@ public class OracleDialectTest extends TestCase {
3928
public void testExpressionFunctions_prefix() throws Exception {
4029
OracleDialect dialect = new OracleDialect();
4130
ExpressionFunctions functions = dialect.getExpressionFunctions();
42-
assertEquals("a$$a$%a$_a$%a$_%", functions.prefix("a$a%a_a%a_"));
31+
assertEquals("a$$a$%a$_a%a_%", functions.prefix("a$a%a_a%a_"));
4332
}
4433

4534
public void testExpressionFunctions_prefix_escape() throws Exception {
4635
OracleDialect dialect = new OracleDialect();
4736
ExpressionFunctions functions = dialect.getExpressionFunctions();
48-
assertEquals("a!!a!%a!_a!%a!_%", functions.prefix("a!a%a_a%a_", '!'));
37+
assertEquals("a!!a!%a!_a%a_%", functions.prefix("a!a%a_a%a_", '!'));
4938
}
5039

5140
public void testExpressionFunctions_prefix_escapeWithBackslash()
5241
throws Exception {
5342
OracleDialect dialect = new OracleDialect();
5443
ExpressionFunctions functions = dialect.getExpressionFunctions();
55-
assertEquals("a\\\\a\\%a\\_a\\%a\\_%",
44+
assertEquals("a\\\\a\\%a\\_a%a_%",
5645
functions.prefix("a\\a%a_a%a_", '\\'));
5746
}
5847

59-
public void testDateFormat() throws Exception {
60-
OracleDialect dialect = new OracleDialect();
61-
SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
62-
DateWrapper wrapper = new DateWrapper(Date.valueOf("2009-01-23"));
63-
assertEquals("date'2009-01-23'",
64-
wrapper.accept(visitor, new ConvertToLogFormatFunction(), null));
65-
}
66-
67-
public void testTimeFormat() throws Exception {
68-
OracleDialect dialect = new OracleDialect();
69-
SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
70-
TimeWrapper wrapper = new TimeWrapper(Time.valueOf("01:23:45"));
71-
assertEquals("time'01:23:45'",
72-
wrapper.accept(visitor, new ConvertToLogFormatFunction(), null));
73-
}
74-
75-
public void testTimestampFormat() throws Exception {
76-
OracleDialect dialect = new OracleDialect();
77-
SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
78-
TimestampWrapper wrapper = new TimestampWrapper(
79-
Timestamp.valueOf("2009-01-23 01:23:45.123456789"));
80-
assertEquals("timestamp'2009-01-23 01:23:45.123456789'",
81-
wrapper.accept(visitor, new ConvertToLogFormatFunction(), null));
82-
}
83-
84-
public void testUtilDateFormat() throws Exception {
85-
OracleDialect dialect = new OracleDialect();
86-
SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
87-
UtilDateWrapper wrapper = new UtilDateWrapper(new SimpleDateFormat(
88-
"yyyy-MM-dd HH:mm:sss.SSS").parse("2009-01-23 12:34:56.789"));
89-
assertEquals("timestamp'2009-01-23 12:34:56.789'",
90-
wrapper.accept(visitor, new ConvertToLogFormatFunction(), null));
91-
}
9248
}

0 commit comments

Comments
 (0)