diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4 b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4 index b30831d67127..757b61e60bf2 100644 --- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4 +++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4 @@ -961,11 +961,11 @@ fragment CN_CHAR ; fragment DQUOTA_STRING - : '"' ( '\\"' | '""' | ~('"') )* '"' + : '"' ( '""' | ~('"') )* '"' ; fragment SQUOTA_STRING - : '\'' ( '\\\'' | '\'\'' | ~('\'') )* '\'' + : '\'' ( '\'\'' | ~('\'') )* '\'' ; fragment BQUOTA_STRING diff --git a/docs/UserGuide/Reference/Syntax-Conventions.md b/docs/UserGuide/Reference/Syntax-Conventions.md index cc5b3ef05774..35e88a5a25a5 100644 --- a/docs/UserGuide/Reference/Syntax-Conventions.md +++ b/docs/UserGuide/Reference/Syntax-Conventions.md @@ -246,7 +246,6 @@ Usages of string literals: There are several ways to include quote characters within a string: - - Precede the quote character by an escape character (\\). - `'` inside a string quoted with `"` needs no special treatment and need not be doubled or escaped. In the same way, `"` inside a string quoted with `'` needs no special treatment. - A `'` inside a string quoted with `'` may be written as `''`. - A `"` inside a string quoted with `"` may be written as `""`. @@ -256,15 +255,11 @@ The following examples demonstrate how quoting and escaping work: 'string' // string '"string"' // "string" '""string""' // ""string"" -'str\'ing' // str'ing -'\'string' // 'string '''string' // 'string "string" // string "'string'" // 'string' "''string''" // ''string'' -"str\"ing" // str"ing -"\"string" // "string """string" // "string ``` diff --git a/docs/zh/UserGuide/Reference/Syntax-Conventions.md b/docs/zh/UserGuide/Reference/Syntax-Conventions.md index 1f543a4c6b72..d2cc8d60f312 100644 --- a/docs/zh/UserGuide/Reference/Syntax-Conventions.md +++ b/docs/zh/UserGuide/Reference/Syntax-Conventions.md @@ -243,11 +243,7 @@ MySQL 对字符串的定义可以参考:[MySQL :: MySQL 8.0 Reference Manual : #### 如何在字符串内使用引号 - 在单引号引起的字符串内,双引号无需特殊处理。同理,在双引号引起的字符串内,单引号无需特殊处理。 - -- 在引号前使用转义符 (\\)。 - - 在单引号引起的字符串里,可以通过双写单引号来表示一个单引号,即单引号 ' 可以表示为 ''。 - - 在双引号引起的字符串里,可以通过双写双引号来表示一个双引号,即双引号 " 可以表示为 ""。 字符串内使用引号的示例如下: @@ -256,15 +252,11 @@ MySQL 对字符串的定义可以参考:[MySQL :: MySQL 8.0 Reference Manual : 'string' // string '"string"' // "string" '""string""' // ""string"" -'str\'ing' // str'ing -'\'string' // 'string '''string' // 'string "string" // string "'string'" // 'string' "''string''" // ''string'' -"str\"ing" // str"ing -"\"string" // "string """string" // "string ``` diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionIdentifierIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionIdentifierIT.java index 74862440a4df..167a4caee830 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionIdentifierIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionIdentifierIT.java @@ -513,6 +513,16 @@ public void testExpression() { } Assert.assertEquals(0, cnt); } + + cnt = 0; + try (ResultSet resultSet = + statement.executeQuery( + "SELECT text FROM root.sg1.d1 where text = '\\' and text = 'asdf'")) { + while (resultSet.next()) { + cnt++; + } + Assert.assertEquals(0, cnt); + } } catch (SQLException e) { e.printStackTrace(); fail(); diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionStringLiteralIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionStringLiteralIT.java index 04642156339a..0104ad8d4e0f 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionStringLiteralIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionStringLiteralIT.java @@ -64,9 +64,7 @@ public void testStringLiteralWithSingleQuote() { "'``string'", "'\"string\"'", "'\"\"string'", - "'\\\"string\\\"'", "'''string'", - "'\\'string'", "'\\nstring'", "'\\rstring'", "'@#$%^&*()string'", @@ -78,8 +76,6 @@ public void testStringLiteralWithSingleQuote() { "``string", "\"string\"", "\"\"string", - "\"string\"", - "'string", "'string", "\\nstring", "\\rstring", @@ -126,9 +122,7 @@ public void testStringLiteralWithDoubleQuote() { "\"``string\"", "\"'string'\"", "\"''string\"", - "\"\\'string\\'\"", "\"\"\"string\"", - "\"\\\"string\"", "\"\\nstring\"", "\"\\rstring\"", "\"@#$%^&*()string\"", @@ -140,8 +134,6 @@ public void testStringLiteralWithDoubleQuote() { "``string", "'string'", "''string", - "'string'", - "\"string", "\"string", "\\nstring", "\\rstring", diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java index bb90418eb455..c766671e841e 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java @@ -1590,8 +1590,7 @@ public long parseDateFormat(String timestampStr, long currentTime) throws SQLPar private String parseStringLiteral(String src) { if (2 <= src.length()) { // do not unescape string - String unWrappedString = - src.substring(1, src.length() - 1).replace("\\\"", "\"").replace("\\'", "'"); + String unWrappedString = src.substring(1, src.length() - 1); if (src.charAt(0) == '\"' && src.charAt(src.length() - 1) == '\"') { // replace "" with " String replaced = unWrappedString.replace("\"\"", "\""); diff --git a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java index 0551aec282f8..153ebb274dbd 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java @@ -3290,8 +3290,7 @@ private boolean hasDecidedQueryType() { private String parseStringLiteral(String src) { if (2 <= src.length()) { // do not unescape string - String unWrappedString = - src.substring(1, src.length() - 1).replace("\\\"", "\"").replace("\\'", "'"); + String unWrappedString = src.substring(1, src.length() - 1); if (src.charAt(0) == '\"' && src.charAt(src.length() - 1) == '\"') { // replace "" with " String replaced = unWrappedString.replace("\"\"", "\"");