Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,13 @@ public Literal visitIntegerLiteral(IntegerLiteralContext ctx) {
public Literal visitStringLiteral(StringLiteralContext ctx) {
String txt = ctx.STRING_LITERAL().getText();
String s = txt.substring(1, txt.length() - 1);
s = s.replace("''", "'").replace("\"\"", "\"");
if (txt.charAt(0) == '\'') {
// for single quote string, '' should be converted to '
s = s.replace("''", "'");
} else if (txt.charAt(0) == '"') {
// for double quote string, "" should be converted to "
s = s.replace("\"\"", "\"");
}
if (!SqlModeHelper.hasNoBackSlashEscapes()) {
s = escapeBackSlash(s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,7 @@ public static String escapeSQL(String str) {
return null;
}
return str.replace("'", "''")
.replace("\\", "\\\\")
.replace("\"", "\"\"");
.replace("\\", "\\\\");
}

public static boolean isExternalTable(String catalogName, String dbName, String tblName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import java.util.ArrayList;
import java.util.Base64;

public class StatisticsUtilTest {
class StatisticsUtilTest {
@Test
public void testConvertToDouble() {
void testConvertToDouble() {
try {
//test DATE
double date1 = StatisticsUtil.convertToDouble(Type.DATE, "1990-01-01");
Expand Down Expand Up @@ -80,7 +80,7 @@ public void testConvertToDouble() {
}

@Test
public void testInAnalyzeTime1() {
void testInAnalyzeTime1() {
new MockUp<StatisticsUtil>() {

@Mock
Expand All @@ -99,7 +99,7 @@ protected SessionVariable findConfigFromGlobalSessionVar(String varName) throws
}

@Test
public void testInAnalyzeTime2() {
void testInAnalyzeTime2() {
new MockUp<StatisticsUtil>() {

@Mock
Expand All @@ -119,7 +119,7 @@ protected SessionVariable findConfigFromGlobalSessionVar(String varName) throws


@Test
public void testEncodeValue() throws Exception {
void testEncodeValue() throws Exception {
Assertions.assertEquals("NULL", StatisticsUtil.encodeValue(null, 0));

ResultRow row = new ResultRow(null);
Expand All @@ -144,10 +144,10 @@ public void testEncodeValue() throws Exception {
}

@Test
public void testEscape() {
void testEscape() {
// \'"
String origin = "\\'\"";
// \\''""
Assertions.assertEquals("\\\\''\"\"", StatisticsUtil.escapeSQL(origin));
Assertions.assertEquals("\\\\''\"", StatisticsUtil.escapeSQL(origin));
}
}