From a9e6e6623007fc49346e233d00bb10d3c7c2c81e Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 10:01:39 +0800 Subject: [PATCH 01/14] feat: add bugs to bypass --- src/sqlancer/stonedb/StoneDBBugs.java | 4 ++++ .../stonedb/gen/StoneDBExpressionGenerator.java | 8 +++++++- src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java | 11 ++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/sqlancer/stonedb/StoneDBBugs.java b/src/sqlancer/stonedb/StoneDBBugs.java index 01040c429..055b43d2c 100644 --- a/src/sqlancer/stonedb/StoneDBBugs.java +++ b/src/sqlancer/stonedb/StoneDBBugs.java @@ -3,6 +3,10 @@ public final class StoneDBBugs { // https://github.com/stoneatom/stonedb/issues/1933 public static boolean bug1933 = true; + // https://github.com/stoneatom/stonedb/issues/1942 + public static boolean bug1942 = true; + // https://github.com/stoneatom/stonedb/issues/1953 + public static boolean bug1953 = true; private StoneDBBugs() { } diff --git a/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java b/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java index a2c239c79..a4a73b78a 100644 --- a/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java +++ b/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java @@ -1,5 +1,7 @@ package sqlancer.stonedb.gen; +import static sqlancer.stonedb.StoneDBBugs.bug1942; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -122,7 +124,11 @@ protected Node generateExpression(int depth) { op = StoneDBUnaryPrefixOperator.getRandom(); return new NewUnaryPrefixOperatorNode<>(generateExpression(depth + 1), op); case UNARY_POSTFIX: - op = StoneDBUnaryPostfixOperator.getRandom(); + if (!bug1942) { + op = StoneDBUnaryPostfixOperator.getRandom(); + } else { + op = StoneDBUnaryPostfixOperator.IS_NULL; + } return new NewUnaryPostfixOperatorNode<>(generateExpression(depth + 1), op); case BINARY_COMPARISON: op = StoneDBBinaryComparisonOperator.getRandom(); diff --git a/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java b/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java index a0506ee83..4754c917d 100644 --- a/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java +++ b/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java @@ -1,5 +1,7 @@ package sqlancer.stonedb.oracle; +import static sqlancer.stonedb.StoneDBBugs.bug1953; + import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -79,6 +81,9 @@ private int getUnoptimizedQueryCount(List> tableList, select.setFromList(tableList); select.setJoinList(joins); unoptimizedQueryString = "SELECT SUM(count) FROM (" + StoneDBToStringVisitor.asString(select) + ") as res;"; + if (bug1953) { + unoptimizedQueryString = "SELECT * FROM (" + StoneDBToStringVisitor.asString(select) + ") as res;"; + } SQLQueryAdapter q = new SQLQueryAdapter(unoptimizedQueryString, errors); SQLancerResultSet rs; try { @@ -90,7 +95,11 @@ private int getUnoptimizedQueryCount(List> tableList, return -1; } int secondCount = 0; - if (rs.next()) { + while (bug1953 && rs.next()) { + secondCount++; + } + if (!bug1953 && rs.next()) { + secondCount = 0; secondCount += rs.getLong(1); } rs.close(); From aecd682bb61512346a8b812252fdbdd85cf3b7d7 Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 11:29:08 +0800 Subject: [PATCH 02/14] fix: change count method --- src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java b/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java index 4754c917d..a1b6c401a 100644 --- a/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java +++ b/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java @@ -96,7 +96,7 @@ private int getUnoptimizedQueryCount(List> tableList, } int secondCount = 0; while (bug1953 && rs.next()) { - secondCount++; + secondCount += rs.getInt(1); } if (!bug1953 && rs.next()) { secondCount = 0; From b96b146adb0bfc3a6d0b68828cd868089f987aef Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 11:33:08 +0800 Subject: [PATCH 03/14] fix: delete unsupported operation --- src/sqlancer/stonedb/ast/StoneDBJoin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sqlancer/stonedb/ast/StoneDBJoin.java b/src/sqlancer/stonedb/ast/StoneDBJoin.java index 9c53316a0..8bfff08ee 100644 --- a/src/sqlancer/stonedb/ast/StoneDBJoin.java +++ b/src/sqlancer/stonedb/ast/StoneDBJoin.java @@ -22,7 +22,7 @@ public static JoinType getRandom() { } public enum NaturalJoinType { - OUTER, LEFT, RIGHT; + LEFT, RIGHT; public static NaturalJoinType getRandom() { return Randomly.fromOptions(values()); From b95761c3a0dcd79f4845a8ff703bf66d04bbbb6d Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 11:37:35 +0800 Subject: [PATCH 04/14] fix: fix unknown error during stonedb setup --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e75be8a0..5d7d2de81 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -388,8 +388,9 @@ jobs: docker run -p 3306:3306 -itd -e MYSQL_ROOT_PASSWORD='123456' stoneatom/stonedb ContainerID=$(docker ps --filter ancestor=stoneatom/stonedb --format "{{.ID}}") docker exec $ContainerID bash - sleep 60s + sleep 30s docker exec $ContainerID sed -i "s/tianmu_insert_delayed=1/tianmu_insert_delayed=0/" /opt/stonedb57/install/my.cnf + sleep 3s docker exec $ContainerID /opt/stonedb57/install/bin/mysql -uroot -p123456 -e "CREATE USER 'sqlancer'@'%' IDENTIFIED WITH mysql_native_password BY 'sqlancer'; GRANT ALL PRIVILEGES ON *.* TO 'sqlancer'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;" - name: Set up JDK 11 uses: actions/setup-java@v1.4.4 From db170fbccc19b7a43356d89dfbfcc937bd687e6b Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 20:16:16 +0800 Subject: [PATCH 05/14] fix: sleep 60s --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5d7d2de81..f86025d1f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -388,7 +388,7 @@ jobs: docker run -p 3306:3306 -itd -e MYSQL_ROOT_PASSWORD='123456' stoneatom/stonedb ContainerID=$(docker ps --filter ancestor=stoneatom/stonedb --format "{{.ID}}") docker exec $ContainerID bash - sleep 30s + sleep 60s docker exec $ContainerID sed -i "s/tianmu_insert_delayed=1/tianmu_insert_delayed=0/" /opt/stonedb57/install/my.cnf sleep 3s docker exec $ContainerID /opt/stonedb57/install/bin/mysql -uroot -p123456 -e "CREATE USER 'sqlancer'@'%' IDENTIFIED WITH mysql_native_password BY 'sqlancer'; GRANT ALL PRIVILEGES ON *.* TO 'sqlancer'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;" From d63570d93b48c32473e69e8774bb8a331392b928 Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 09:30:53 +0800 Subject: [PATCH 06/14] refactor: delete useless try catch --- src/sqlancer/DatabaseProvider.java | 2 +- src/sqlancer/stonedb/StoneDBProvider.java | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/sqlancer/DatabaseProvider.java b/src/sqlancer/DatabaseProvider.java index d169324fa..3ea5f51d1 100644 --- a/src/sqlancer/DatabaseProvider.java +++ b/src/sqlancer/DatabaseProvider.java @@ -5,7 +5,7 @@ public interface DatabaseProvider, O extends DBMSSpecificOptions, C extends SQLancerDBConnection> { /** - * Gets the the {@link GlobalState} class. + * Gets the {@link GlobalState} class. * * @return the class extending {@link GlobalState} */ diff --git a/src/sqlancer/stonedb/StoneDBProvider.java b/src/sqlancer/stonedb/StoneDBProvider.java index e0c317c53..16b936e61 100644 --- a/src/sqlancer/stonedb/StoneDBProvider.java +++ b/src/sqlancer/stonedb/StoneDBProvider.java @@ -127,11 +127,7 @@ public SQLConnection createDatabase(StoneDBGlobalState globalState) throws Excep Connection con = DriverManager.getConnection(url, username, password); try (Statement s = con.createStatement()) { s.execute("DROP DATABASE IF EXISTS " + databaseName); - } - try (Statement s = con.createStatement()) { s.execute("CREATE DATABASE " + databaseName); - } - try (Statement s = con.createStatement()) { s.execute("USE " + databaseName); } return new SQLConnection(con); From e2c6b2e6bfe7251b30f52ac10774be45e8d7043d Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 11:10:43 +0800 Subject: [PATCH 07/14] fix: do not use new randomly but use global randomly --- src/sqlancer/stonedb/StoneDBSchema.java | 14 +++++++------- .../stonedb/gen/StoneDBTableAlterGenerator.java | 6 ++++-- .../stonedb/gen/StoneDBTableCreateGenerator.java | 2 +- .../stonedb/gen/StoneDBTableUpdateGenerator.java | 9 ++++----- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/sqlancer/stonedb/StoneDBSchema.java b/src/sqlancer/stonedb/StoneDBSchema.java index aa0e764f6..17d2fccea 100644 --- a/src/sqlancer/stonedb/StoneDBSchema.java +++ b/src/sqlancer/stonedb/StoneDBSchema.java @@ -36,7 +36,7 @@ public static StoneDBDataType getRandom() { return Randomly.fromOptions(values()); } - public static Node getRandomValue(StoneDBDataType dataType) { + public static Node getRandomValue(StoneDBDataType dataType, Randomly r) { switch (dataType) { case TINYINT: break; @@ -72,7 +72,7 @@ public static Node getRandomValue(StoneDBDataType dataType) { break; case TEXT: StringGenerationStrategy strategy = StringGenerationStrategy.ALPHANUMERIC; - String str = strategy.getString(new Randomly()); + String str = strategy.getString(r); return StoneDBConstant.createTextConstant(str); case MEDIUMTEXT: break; @@ -96,7 +96,7 @@ public static Node getRandomValue(StoneDBDataType dataType) { return null; } - public static String getTypeAndValue(StoneDBDataType dataType) { + public static String getTypeAndValue(StoneDBDataType dataType, Randomly r) { StringBuilder sb = new StringBuilder(); switch (dataType) { case TINYINT: @@ -130,10 +130,10 @@ public static String getTypeAndValue(StoneDBDataType dataType) { case TIMESTAMP: return "TIMESTAMP"; case CHAR: - sb.append("CHAR").append(Randomly.fromOptions("", "(" + new Randomly().getInteger(0, 255) + ")")); + sb.append("CHAR").append(Randomly.fromOptions("", "(" + r.getInteger(0, 255) + ")")); return sb.toString(); case VARCHAR: - sb.append("VARCHAR").append("(").append(new Randomly().getInteger(0, 65535)).append(")"); + sb.append("VARCHAR").append("(").append(r.getInteger(0, 65535)).append(")"); return sb.toString(); case TINYTEXT: return "TINYTEXT"; @@ -144,10 +144,10 @@ public static String getTypeAndValue(StoneDBDataType dataType) { case LONGTEXT: return "LONGTEXT"; case BINARY: - sb.append("BINARY").append("(").append(new Randomly().getInteger(0, 255)).append(")"); + sb.append("BINARY").append("(").append(r.getInteger(0, 255)).append(")"); return sb.toString(); case VARBINARY: - sb.append("VARBINARY").append("(").append(new Randomly().getInteger(0, 65535)).append(")"); + sb.append("VARBINARY").append("(").append(r.getInteger(0, 65535)).append(")"); return sb.toString(); case TINYBLOB: return "TINYBLOB"; diff --git a/src/sqlancer/stonedb/gen/StoneDBTableAlterGenerator.java b/src/sqlancer/stonedb/gen/StoneDBTableAlterGenerator.java index 2f0471316..fa5b46d7d 100644 --- a/src/sqlancer/stonedb/gen/StoneDBTableAlterGenerator.java +++ b/src/sqlancer/stonedb/gen/StoneDBTableAlterGenerator.java @@ -71,7 +71,8 @@ private void appendAlterOption(Action action) { sb.append("ADD COLUMN "); String columnName = table.getFreeColumnName(); sb.append(" ").append(columnName).append(" "); - sb.append(StoneDBDataType.getTypeAndValue(StoneDBDataType.getRandomWithoutNull())); + sb.append( + StoneDBDataType.getTypeAndValue(StoneDBDataType.getRandomWithoutNull(), globalState.getRandomly())); // java.sql.SQLSyntaxErrorException: Column length too big for column 'c1' (max = 16383); use BLOB or TEXT // instead errors.addRegex(Pattern @@ -105,7 +106,8 @@ private void appendAlterOption(Action action) { String oldColumnName = table.getRandomColumn().getName(); String newColumnName = table.getFreeColumnName(); sb.append(oldColumnName).append(" ").append(newColumnName).append(" "); - sb.append(StoneDBDataType.getTypeAndValue(StoneDBDataType.getRandomWithoutNull())); + sb.append( + StoneDBDataType.getTypeAndValue(StoneDBDataType.getRandomWithoutNull(), globalState.getRandomly())); // java.sql.SQLSyntaxErrorException: Column length too big for column 'c1' (max = 16383); use BLOB or TEXT // instead errors.addRegex(Pattern diff --git a/src/sqlancer/stonedb/gen/StoneDBTableCreateGenerator.java b/src/sqlancer/stonedb/gen/StoneDBTableCreateGenerator.java index 3b87e99d5..c288c57fd 100644 --- a/src/sqlancer/stonedb/gen/StoneDBTableCreateGenerator.java +++ b/src/sqlancer/stonedb/gen/StoneDBTableCreateGenerator.java @@ -261,6 +261,6 @@ private void appendColumnOption(StoneDBDataType type) { } private void appendType(StoneDBDataType randomType) { - sb.append(StoneDBDataType.getTypeAndValue(randomType)); + sb.append(StoneDBDataType.getTypeAndValue(randomType, r)); } } diff --git a/src/sqlancer/stonedb/gen/StoneDBTableUpdateGenerator.java b/src/sqlancer/stonedb/gen/StoneDBTableUpdateGenerator.java index 4812a6ee3..259136135 100644 --- a/src/sqlancer/stonedb/gen/StoneDBTableUpdateGenerator.java +++ b/src/sqlancer/stonedb/gen/StoneDBTableUpdateGenerator.java @@ -49,11 +49,10 @@ public void appendAssignmentList() { } sb.append(table.getColumns().get(i)); sb.append(" = "); - sb.append( - Randomly.fromOptions( - StoneDBToStringVisitor.asString(StoneDBSchema.StoneDBDataType - .getRandomValue(table.getColumns().get(i).getType().getPrimitiveDataType())), - "DEFAULT")); + sb.append(Randomly.fromOptions( + StoneDBToStringVisitor.asString(StoneDBSchema.StoneDBDataType.getRandomValue( + table.getColumns().get(i).getType().getPrimitiveDataType(), globalState.getRandomly())), + "DEFAULT")); } } From 98c9cc05011ebc0fe8ae025edba6d12cf0eb7ebe Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 11:21:15 +0800 Subject: [PATCH 08/14] fix: do not delete useful --- src/sqlancer/stonedb/ast/StoneDBJoin.java | 2 +- src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sqlancer/stonedb/ast/StoneDBJoin.java b/src/sqlancer/stonedb/ast/StoneDBJoin.java index 8bfff08ee..9c53316a0 100644 --- a/src/sqlancer/stonedb/ast/StoneDBJoin.java +++ b/src/sqlancer/stonedb/ast/StoneDBJoin.java @@ -22,7 +22,7 @@ public static JoinType getRandom() { } public enum NaturalJoinType { - LEFT, RIGHT; + OUTER, LEFT, RIGHT; public static NaturalJoinType getRandom() { return Randomly.fromOptions(values()); diff --git a/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java b/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java index a4a73b78a..55eafd352 100644 --- a/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java +++ b/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java @@ -262,7 +262,7 @@ public String getTextRepresentation() { */ public enum StoneDBBinaryLogicalOperator implements Operator { - AND("AND"), OR("OR"); + AND("AND"), OR("OR"), XOR("XOR"); private final String textRepr; From 37970b514268313c2137679c95303910a09a3055 Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sat, 29 Jul 2023 20:47:56 +0800 Subject: [PATCH 09/14] fix: --- src/sqlancer/stonedb/ast/StoneDBJoin.java | 2 +- src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sqlancer/stonedb/ast/StoneDBJoin.java b/src/sqlancer/stonedb/ast/StoneDBJoin.java index 9c53316a0..8bfff08ee 100644 --- a/src/sqlancer/stonedb/ast/StoneDBJoin.java +++ b/src/sqlancer/stonedb/ast/StoneDBJoin.java @@ -22,7 +22,7 @@ public static JoinType getRandom() { } public enum NaturalJoinType { - OUTER, LEFT, RIGHT; + LEFT, RIGHT; public static NaturalJoinType getRandom() { return Randomly.fromOptions(values()); diff --git a/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java b/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java index 55eafd352..5f8b22fac 100644 --- a/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java +++ b/src/sqlancer/stonedb/gen/StoneDBExpressionGenerator.java @@ -89,7 +89,7 @@ public Node generateConstant(StoneDBDataType dataType) { return StoneDBConstant.createTimestampConstant(globalState.getRandomly().getInteger()); case VARCHAR: StringGenerationStrategy strategy = StringGenerationStrategy.ALPHANUMERIC; - String str = strategy.getString(new Randomly()); + String str = strategy.getString(globalState.getRandomly()); return StoneDBConstant.createTextConstant(str); case DOUBLE: return StoneDBConstant.createDoubleConstant(globalState.getRandomly().getDouble()); From ff002867afc691e3ba97db1c3ed57f5f8895872b Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sun, 30 Jul 2023 10:58:27 +0800 Subject: [PATCH 10/14] fix: let DateTime to be valid --- .github/workflows/main.yml | 2 +- src/sqlancer/stonedb/ast/StoneDBConstant.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f86025d1f..78a5cd3cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -390,7 +390,7 @@ jobs: docker exec $ContainerID bash sleep 60s docker exec $ContainerID sed -i "s/tianmu_insert_delayed=1/tianmu_insert_delayed=0/" /opt/stonedb57/install/my.cnf - sleep 3s + sleep 60s docker exec $ContainerID /opt/stonedb57/install/bin/mysql -uroot -p123456 -e "CREATE USER 'sqlancer'@'%' IDENTIFIED WITH mysql_native_password BY 'sqlancer'; GRANT ALL PRIVILEGES ON *.* TO 'sqlancer'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;" - name: Set up JDK 11 uses: actions/setup-java@v1.4.4 diff --git a/src/sqlancer/stonedb/ast/StoneDBConstant.java b/src/sqlancer/stonedb/ast/StoneDBConstant.java index f0abae48a..e8ddf557e 100644 --- a/src/sqlancer/stonedb/ast/StoneDBConstant.java +++ b/src/sqlancer/stonedb/ast/StoneDBConstant.java @@ -160,6 +160,15 @@ public static class StoneDBTimestampConstant extends StoneDBConstant { public String textRepr; public StoneDBTimestampConstant(long val) { + long validValue = val; + // 9999-12-31 23:59:59.000999 + if (validValue > 253402271999999L) { + validValue = 253402271999999L; + } + // 1000-01-01 00:00:00.000000 + if (validValue < -30609820800000L) { + validValue = -30609820800000L; + } Timestamp timestamp = new Timestamp(val); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); textRepr = dateFormat.format(timestamp); From a84170a9d4ba27460f32d138f0407c88e3b1e302 Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Sun, 30 Jul 2023 15:01:52 +0800 Subject: [PATCH 11/14] fix: delete useless expected errors --- src/sqlancer/stonedb/StoneDBErrors.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sqlancer/stonedb/StoneDBErrors.java b/src/sqlancer/stonedb/StoneDBErrors.java index 10c8ee9e3..adf7568f5 100644 --- a/src/sqlancer/stonedb/StoneDBErrors.java +++ b/src/sqlancer/stonedb/StoneDBErrors.java @@ -7,8 +7,6 @@ private StoneDBErrors() { } public static void addExpectedExpressionErrors(ExpectedErrors errors) { - // java.sql.SQLException: Incorrect DATETIME value: '292269055-12-02 16:47:04' - errors.add("Incorrect DATETIME value: "); // java.sql.SQLException: Incorrect DATE value: '292269055-12-02' errors.add("Incorrect DATE value: "); // java.sql.SQLException: Incorrect string value: '\xBC\xE7\xC9\x91\x05R...' for column 'c1' at row 1 From 3570d04c45342e0116e3caf57501c96753982939 Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Mon, 31 Jul 2023 10:39:11 +0800 Subject: [PATCH 12/14] fix: call re.next() only once --- .../stonedb/oracle/StoneDBNoRECOracle.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java b/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java index a1b6c401a..a6ffb9bfe 100644 --- a/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java +++ b/src/sqlancer/stonedb/oracle/StoneDBNoRECOracle.java @@ -95,12 +95,14 @@ private int getUnoptimizedQueryCount(List> tableList, return -1; } int secondCount = 0; - while (bug1953 && rs.next()) { - secondCount += rs.getInt(1); - } - if (!bug1953 && rs.next()) { - secondCount = 0; - secondCount += rs.getLong(1); + if (bug1953) { + while (rs.next()) { + secondCount += rs.getInt(1); + } + } else { + if (rs.next()) { + secondCount += rs.getLong(1); + } } rs.close(); return secondCount; From 6e8e0782d599f4a9e7145ad26f362cea1a9b0ad7 Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Mon, 31 Jul 2023 11:23:00 +0800 Subject: [PATCH 13/14] fix: let DateTime to be valid --- src/sqlancer/stonedb/ast/StoneDBConstant.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sqlancer/stonedb/ast/StoneDBConstant.java b/src/sqlancer/stonedb/ast/StoneDBConstant.java index e8ddf557e..023ff888a 100644 --- a/src/sqlancer/stonedb/ast/StoneDBConstant.java +++ b/src/sqlancer/stonedb/ast/StoneDBConstant.java @@ -135,6 +135,15 @@ public static class StoneDBDateConstant extends StoneDBConstant { public String textRepr; public StoneDBDateConstant(long val) { + long validValue = val; + // 9999-12-31 23:59:59.000999 + if (validValue > 253402271999999L) { + validValue = 253402271999999L; + } + // 1000-01-01 00:00:00.000000 + if (validValue < -30609820800000L) { + validValue = -30609820800000L; + } Timestamp timestamp = new Timestamp(val); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); textRepr = dateFormat.format(timestamp); From 9cbfbcd236e7dde8858603d25c26a342dc61edd4 Mon Sep 17 00:00:00 2001 From: zhenglinli <1125806272@qq.com> Date: Mon, 31 Jul 2023 11:27:14 +0800 Subject: [PATCH 14/14] fix: let DateTime to be valid --- src/sqlancer/stonedb/ast/StoneDBConstant.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sqlancer/stonedb/ast/StoneDBConstant.java b/src/sqlancer/stonedb/ast/StoneDBConstant.java index 023ff888a..341ca8d2d 100644 --- a/src/sqlancer/stonedb/ast/StoneDBConstant.java +++ b/src/sqlancer/stonedb/ast/StoneDBConstant.java @@ -144,7 +144,7 @@ public StoneDBDateConstant(long val) { if (validValue < -30609820800000L) { validValue = -30609820800000L; } - Timestamp timestamp = new Timestamp(val); + Timestamp timestamp = new Timestamp(validValue); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); textRepr = dateFormat.format(timestamp); } @@ -178,7 +178,7 @@ public StoneDBTimestampConstant(long val) { if (validValue < -30609820800000L) { validValue = -30609820800000L; } - Timestamp timestamp = new Timestamp(val); + Timestamp timestamp = new Timestamp(validValue); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); textRepr = dateFormat.format(timestamp); }