From 63e7ff866581368662b502ba1cb0eb9cf6753050 Mon Sep 17 00:00:00 2001 From: ZhengLin Li <1125806272@qq.com> Date: Tue, 20 Jun 2023 23:10:02 +0800 Subject: [PATCH] fix: fix errors in mvn verify -DskipTests --- src/sqlancer/Randomly.java | 6 +- src/sqlancer/stonedb/StoneDBOptions.java | 9 +- src/sqlancer/stonedb/StoneDBProvider.java | 21 +- src/sqlancer/stonedb/StoneDBSchema.java | 192 ++++++++++++------ .../stonedb/gen/StoneDBTableGenerator.java | 25 +-- .../stonedb/oracle/StoneDBTLPOracle.java | 2 +- 6 files changed, 166 insertions(+), 89 deletions(-) diff --git a/src/sqlancer/Randomly.java b/src/sqlancer/Randomly.java index fab1902b5..fc8ab2a27 100644 --- a/src/sqlancer/Randomly.java +++ b/src/sqlancer/Randomly.java @@ -2,7 +2,11 @@ import java.math.BigDecimal; import java.math.BigInteger; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Random; import java.util.function.Supplier; public final class Randomly { diff --git a/src/sqlancer/stonedb/StoneDBOptions.java b/src/sqlancer/stonedb/StoneDBOptions.java index 849d30a29..928bcfa39 100644 --- a/src/sqlancer/stonedb/StoneDBOptions.java +++ b/src/sqlancer/stonedb/StoneDBOptions.java @@ -1,7 +1,12 @@ package sqlancer.stonedb; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.List; + import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; + import sqlancer.DBMSSpecificOptions; import sqlancer.OracleFactory; import sqlancer.common.oracle.TestOracle; @@ -10,10 +15,6 @@ import sqlancer.stonedb.oracle.StoneDBNoRECOracle; import sqlancer.stonedb.oracle.StoneDBTLPOracle; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.List; - @Parameters(separators = "=", commandDescription = "StoneDB (default host: " + StoneDBOptions.DEFAULT_HOST + ", default port: " + StoneDBOptions.DEFAULT_PORT + ")") public class StoneDBOptions implements DBMSSpecificOptions { diff --git a/src/sqlancer/stonedb/StoneDBProvider.java b/src/sqlancer/stonedb/StoneDBProvider.java index 032a5943c..31a99a26d 100644 --- a/src/sqlancer/stonedb/StoneDBProvider.java +++ b/src/sqlancer/stonedb/StoneDBProvider.java @@ -1,17 +1,26 @@ package sqlancer.stonedb; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; + import com.google.auto.service.AutoService; -import sqlancer.*; + +import sqlancer.AbstractAction; +import sqlancer.DatabaseProvider; +import sqlancer.IgnoreMeException; +import sqlancer.MainOptions; +import sqlancer.Randomly; +import sqlancer.SQLConnection; +import sqlancer.SQLGlobalState; +import sqlancer.SQLProviderAdapter; +import sqlancer.StatementExecutor; import sqlancer.common.DBMSCommon; import sqlancer.common.query.Query; import sqlancer.common.query.SQLQueryAdapter; import sqlancer.common.query.SQLQueryProvider; import sqlancer.stonedb.gen.StoneDBTableGenerator; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.Statement; - @AutoService(DatabaseProvider.class) public class StoneDBProvider extends SQLProviderAdapter { @@ -42,7 +51,7 @@ public Query getQuery(StoneDBGlobalState globalState) throws Exception { } private static int mapActions(StoneDBGlobalState globalState, Action a) { - Randomly r = globalState.getRandomly(); + globalState.getRandomly(); switch (a) { case SHOW_TABLES: return 1; diff --git a/src/sqlancer/stonedb/StoneDBSchema.java b/src/sqlancer/stonedb/StoneDBSchema.java index 65f369a35..93678e511 100644 --- a/src/sqlancer/stonedb/StoneDBSchema.java +++ b/src/sqlancer/stonedb/StoneDBSchema.java @@ -1,5 +1,10 @@ package sqlancer.stonedb; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + import sqlancer.Randomly; import sqlancer.SQLConnection; import sqlancer.common.schema.AbstractRelationalTable; @@ -7,11 +12,6 @@ import sqlancer.common.schema.AbstractTableColumn; import sqlancer.common.schema.TableIndex; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - public class StoneDBSchema extends AbstractSchema { public enum StoneDBDataType { @@ -192,62 +192,63 @@ private static StoneDBCompositeDataType getColumnCompositeDataType(String typeSt } } - private static StoneDBDataType getColumnType(String typeString) { - switch (typeString) { - case "tinyint": - return StoneDBDataType.TINYINT; - case "smallint": - return StoneDBDataType.SMALLINT; - case "mediumint": - return StoneDBDataType.MEDIUMINT; - case "int": - return StoneDBDataType.INT; - case "bigint": - return StoneDBDataType.BIGINT; - case "float": - return StoneDBDataType.FLOAT; - case "double": - return StoneDBDataType.DOUBLE; - case "decimal": - return StoneDBDataType.DECIMAL; - case "year": - return StoneDBDataType.YEAR; - case "time": - return StoneDBDataType.TIME; - case "date": - return StoneDBDataType.DATE; - case "datetime": - return StoneDBDataType.DATETIME; - case "timestamp": - return StoneDBDataType.TIMESTAMP; - case "char": - return StoneDBDataType.CHAR; - case "varchar": - return StoneDBDataType.VARCHAR; - case "tinytext": - return StoneDBDataType.TINYTEXT; - case "text": - return StoneDBDataType.TEXT; - case "mediumtext": - return StoneDBDataType.MEDIUMTEXT; - case "longtext": - return StoneDBDataType.LONGTEXT; - case "binary": - return StoneDBDataType.BINARY; - case "varbinary": - return StoneDBDataType.VARBINARY; - case "tinyblob": - return StoneDBDataType.TINYBLOB; - case "blob": - return StoneDBDataType.BLOB; - case "mediumblob": - return StoneDBDataType.MEDIUMBLOB; - case "longblob": - return StoneDBDataType.LONGBLOB; - default: - throw new AssertionError(typeString); - } - } + // + // private static StoneDBDataType getColumnType(String typeString) { + // switch (typeString) { + // case "tinyint": + // return StoneDBDataType.TINYINT; + // case "smallint": + // return StoneDBDataType.SMALLINT; + // case "mediumint": + // return StoneDBDataType.MEDIUMINT; + // case "int": + // return StoneDBDataType.INT; + // case "bigint": + // return StoneDBDataType.BIGINT; + // case "float": + // return StoneDBDataType.FLOAT; + // case "double": + // return StoneDBDataType.DOUBLE; + // case "decimal": + // return StoneDBDataType.DECIMAL; + // case "year": + // return StoneDBDataType.YEAR; + // case "time": + // return StoneDBDataType.TIME; + // case "date": + // return StoneDBDataType.DATE; + // case "datetime": + // return StoneDBDataType.DATETIME; + // case "timestamp": + // return StoneDBDataType.TIMESTAMP; + // case "char": + // return StoneDBDataType.CHAR; + // case "varchar": + // return StoneDBDataType.VARCHAR; + // case "tinytext": + // return StoneDBDataType.TINYTEXT; + // case "text": + // return StoneDBDataType.TEXT; + // case "mediumtext": + // return StoneDBDataType.MEDIUMTEXT; + // case "longtext": + // return StoneDBDataType.LONGTEXT; + // case "binary": + // return StoneDBDataType.BINARY; + // case "varbinary": + // return StoneDBDataType.VARBINARY; + // case "tinyblob": + // return StoneDBDataType.TINYBLOB; + // case "blob": + // return StoneDBDataType.BLOB; + // case "mediumblob": + // return StoneDBDataType.MEDIUMBLOB; + // case "longblob": + // return StoneDBDataType.LONGBLOB; + // default: + // throw new AssertionError(typeString); + // } + // } private static List getTableNames(SQLConnection con, String databaseName) throws SQLException { List tableNames = new ArrayList<>(); @@ -285,6 +286,10 @@ public boolean isNullable() { return isNullable; } + public int getPrecision() { + return precision; + } + } public StoneDBSchema(List databaseTables) { @@ -293,7 +298,7 @@ public StoneDBSchema(List databaseTables) { public static class StoneDBCompositeDataType { private final StoneDBDataType dataType; - private int size; + private final int size; public StoneDBCompositeDataType(StoneDBDataType dataType, int size) { this.dataType = dataType; @@ -302,7 +307,7 @@ public StoneDBCompositeDataType(StoneDBDataType dataType, int size) { public StoneDBCompositeDataType(StoneDBDataType dataType) { this.dataType = dataType; - size = -1; + int size = -1; switch (dataType) { case TINYINT: size = 1; @@ -325,8 +330,65 @@ public StoneDBCompositeDataType(StoneDBDataType dataType) { case DOUBLE: size = 8; break; - // TODO: ADD MORE DATA TYPE + case DECIMAL: + size = -2; + break; + case YEAR: + size = -2; + break; + case TIME: + size = -2; + break; + case DATE: + size = -2; + break; + case DATETIME: + size = -2; + break; + case TIMESTAMP: + size = -2; + break; + case CHAR: + size = -2; + break; + case VARCHAR: + size = -2; + break; + case TINYTEXT: + size = -2; + break; + case TEXT: + size = -2; + break; + case MEDIUMTEXT: + size = -2; + break; + case LONGTEXT: + size = -2; + break; + case BINARY: + size = -2; + break; + case VARBINARY: + size = -2; + break; + case TINYBLOB: + size = -2; + break; + case BLOB: + size = -2; + break; + case MEDIUMBLOB: + size = -2; + break; + case LONGBLOB: + size = -2; + break; + default: + size = -1; + throw new AssertionError(); } + this.size = size; } public StoneDBDataType getPrimitiveDataType() { @@ -340,4 +402,4 @@ public int getSize() { return size; } } -} \ No newline at end of file +} diff --git a/src/sqlancer/stonedb/gen/StoneDBTableGenerator.java b/src/sqlancer/stonedb/gen/StoneDBTableGenerator.java index 7c2489624..f7847b4a5 100644 --- a/src/sqlancer/stonedb/gen/StoneDBTableGenerator.java +++ b/src/sqlancer/stonedb/gen/StoneDBTableGenerator.java @@ -1,19 +1,18 @@ package sqlancer.stonedb.gen; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + import sqlancer.Randomly; import sqlancer.common.DBMSCommon; import sqlancer.common.query.ExpectedErrors; import sqlancer.common.query.SQLQueryAdapter; -import sqlancer.mysql.MySQLBugs; import sqlancer.stonedb.StoneDBProvider.StoneDBGlobalState; import sqlancer.stonedb.StoneDBSchema; import sqlancer.stonedb.StoneDBSchema.StoneDBDataType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - public class StoneDBTableGenerator { private final String tableName; private final StoneDBSchema schema; @@ -190,10 +189,10 @@ private void appendColumnOption(StoneDBDataType type) { boolean isNull = false; boolean columnHasPrimaryKey = false; List columnOptions = Randomly.subset(ColumnOptions.values()); - boolean tableHasNullableColumn; - if (!columnOptions.contains(ColumnOptions.NULL_OR_NOT_NULL)) { - tableHasNullableColumn = true; - } + // boolean tableHasNullableColumn; + // if (!columnOptions.contains(ColumnOptions.NULL_OR_NOT_NULL)) { + // tableHasNullableColumn = true; + // } if (isTextType) { // TODO: restriction due to the limited key length columnOptions.remove(ColumnOptions.PRIMARY_KEY); @@ -208,7 +207,7 @@ private void appendColumnOption(StoneDBDataType type) { if (Randomly.getBoolean()) { sb.append("NULL"); } - tableHasNullableColumn = true; + // tableHasNullableColumn = true; isNull = true; } else { sb.append("NOT NULL"); @@ -333,11 +332,13 @@ private void appendType(StoneDBDataType randomType) { case LONGBLOB: sb.append("LONGBLOB"); break; + default: + throw new AssertionError(); } } public static void optionallyAddPrecisionAndScale(StringBuilder sb) { - if (Randomly.getBoolean() && !MySQLBugs.bug99183) { + if (Randomly.getBoolean()) { sb.append("("); // The maximum number of digits (M) for DECIMAL is 65 long m = Randomly.getNotCachedInteger(1, 65); diff --git a/src/sqlancer/stonedb/oracle/StoneDBTLPOracle.java b/src/sqlancer/stonedb/oracle/StoneDBTLPOracle.java index a0080f353..96deda89e 100644 --- a/src/sqlancer/stonedb/oracle/StoneDBTLPOracle.java +++ b/src/sqlancer/stonedb/oracle/StoneDBTLPOracle.java @@ -13,4 +13,4 @@ public StoneDBTLPOracle(StoneDBGlobalState state) { public void check() throws Exception { } -} \ No newline at end of file +}