Skip to content

Commit

Permalink
fix: fix errors in mvn verify -DskipTests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengLin Li authored and zhenglin-charlie-li committed Jun 23, 2023
1 parent 46f45e9 commit 63e7ff8
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 89 deletions.
6 changes: 5 additions & 1 deletion src/sqlancer/Randomly.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions src/sqlancer/stonedb/StoneDBOptions.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<StoneDBOracleFactory> {
Expand Down
21 changes: 15 additions & 6 deletions src/sqlancer/stonedb/StoneDBProvider.java
Original file line number Diff line number Diff line change
@@ -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<StoneDBProvider.StoneDBGlobalState, StoneDBOptions> {

Expand Down Expand Up @@ -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;
Expand Down
192 changes: 127 additions & 65 deletions src/sqlancer/stonedb/StoneDBSchema.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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;
import sqlancer.common.schema.AbstractSchema;
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<StoneDBProvider.StoneDBGlobalState, StoneDBSchema.StoneDBTable> {

public enum StoneDBDataType {
Expand Down Expand Up @@ -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<String> getTableNames(SQLConnection con, String databaseName) throws SQLException {
List<String> tableNames = new ArrayList<>();
Expand Down Expand Up @@ -285,6 +286,10 @@ public boolean isNullable() {
return isNullable;
}

public int getPrecision() {
return precision;
}

}

public StoneDBSchema(List<StoneDBTable> databaseTables) {
Expand All @@ -293,7 +298,7 @@ public StoneDBSchema(List<StoneDBTable> 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;
Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -340,4 +402,4 @@ public int getSize() {
return size;
}
}
}
}
25 changes: 13 additions & 12 deletions src/sqlancer/stonedb/gen/StoneDBTableGenerator.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -190,10 +189,10 @@ private void appendColumnOption(StoneDBDataType type) {
boolean isNull = false;
boolean columnHasPrimaryKey = false;
List<ColumnOptions> 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);
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/sqlancer/stonedb/oracle/StoneDBTLPOracle.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public StoneDBTLPOracle(StoneDBGlobalState state) {
public void check() throws Exception {

}
}
}

0 comments on commit 63e7ff8

Please sign in to comment.