Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b7501c7
suuport host/port arguments for postgres
abcdabcd3899 Mar 9, 2021
5fac753
support host/port arguments for MySQL
abcdabcd3899 Mar 9, 2021
96f22a0
support host/port arguments for mariadb
abcdabcd3899 Mar 9, 2021
3051257
support host/port arguments for clickhouse
abcdabcd3899 Mar 9, 2021
33b9ef9
support host/port arguments for cockroachdb
abcdabcd3899 Mar 9, 2021
fceb0ac
support host/port arguments for TiDB
abcdabcd3899 Mar 9, 2021
decb8ff
format
abcdabcd3899 Mar 9, 2021
4618937
modify format
abcdabcd3899 Mar 9, 2021
1ca57bf
Update TiDBProvider.java
Mar 9, 2021
7a3ebf4
Update Main.java
Mar 12, 2021
03f8d6f
modify typo error
Mar 17, 2021
17e79ae
using String.format replace + in String
abcdabcd3899 Mar 18, 2021
4b45629
adding the help text and modifing the default values of host and port
abcdabcd3899 Mar 20, 2021
9a5370b
Merge remote-tracking branch 'upstream/master'
abcdabcd3899 Mar 20, 2021
f201549
constant representation for the default value of host and port
abcdabcd3899 Mar 20, 2021
dc2bc44
delete comments
abcdabcd3899 Mar 20, 2021
ba7d856
Merge remote-tracking branch 'upstream/master'
abcdabcd3899 Mar 25, 2021
c601f4f
add constant support for the different DBMSs
abcdabcd3899 Mar 25, 2021
ddd2d02
add constant support for the different DBMSs
abcdabcd3899 Mar 25, 2021
b931c73
Merge branch 'master' of https://github.com/EthanDBer/sqlancer
abcdabcd3899 Mar 25, 2021
c520480
add const support for the different DBMSs and use local variables
abcdabcd3899 Mar 25, 2021
318272f
Delete 1
Mar 25, 2021
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
2 changes: 1 addition & 1 deletion src/sqlancer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private String formatInteger(long intValue) {
.testConnection();
} catch (Exception e) {
System.err.println(
"SQLancer failed creating a test database, indicating that SQLancer might have failed connecting to the DBMS. In order to change the username and password, you can use the --username and --password options. Currently, SQLancer does not yet support passing a host and port (see https://github.com/sqlancer/sqlancer/issues/95).\n\n");
"SQLancer failed creating a test database, indicating that SQLancer might have failed connecting to the DBMS. In order to change the username, password, host and port, you can use the --username, --password, --host and --port options.\n\n");
e.printStackTrace();
return options.getErrorExitCode();
}
Expand Down
15 changes: 15 additions & 0 deletions src/sqlancer/MainOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@Parameters(separators = "=", commandDescription = "Options applicable to all DBMS")
public class MainOptions {
public static final int NO_SET_PORT = -1;

@Parameter(names = { "--help", "-h" }, description = "Lists all supported options and commands", help = true)
private boolean help; // NOPMD
Expand Down Expand Up @@ -49,6 +50,12 @@ public class MainOptions {
@Parameter(names = "--password", description = "The password used to log into the DBMS")
private String password = "sqlancer"; // NOPMD

@Parameter(names = "--host", description = "The host used to log into the DBMS")
private String host = null; // NOPMD

@Parameter(names = "--port", description = "The port used to log into the DBMS")
private int port = MainOptions.NO_SET_PORT; // NOPMD

@Parameter(names = "--print-progress-information", description = "Whether to print progress information such as the number of databases generated or queries issued", arity = 1)
private boolean printProgressInformation = true; // NOPMD

Expand Down Expand Up @@ -151,6 +158,14 @@ public String getPassword() {
return password;
}

public String getHost() {
return host;
}

public int getPort() {
return port;
}

public boolean printProgressInformation() {
return printProgressInformation;
}
Expand Down
5 changes: 4 additions & 1 deletion src/sqlancer/clickhouse/ClickHouseOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import sqlancer.clickhouse.oracle.tlp.ClickHouseTLPWhereOracle;
import sqlancer.common.oracle.TestOracle;

@Parameters(separators = "=", commandDescription = "ClickHouse")
@Parameters(separators = "=", commandDescription = "ClickHouse (default port: " + ClickHouseOptions.DEFAULT_PORT
+ ", default host: " + ClickHouseOptions.DEFAULT_HOST)
public class ClickHouseOptions implements DBMSSpecificOptions<ClickHouseOracleFactory> {
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 8123;

@Parameter(names = "--oracle")
public List<ClickHouseOracleFactory> oracle = Arrays.asList(ClickHouseOracleFactory.TLPWhere);
Expand Down
12 changes: 11 additions & 1 deletion src/sqlancer/clickhouse/ClickHouseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import sqlancer.AbstractAction;
import sqlancer.IgnoreMeException;
import sqlancer.MainOptions;
import sqlancer.Randomly;
import sqlancer.SQLConnection;
import sqlancer.SQLGlobalState;
Expand Down Expand Up @@ -102,9 +103,18 @@ public void generateDatabase(ClickHouseGlobalState globalState) throws Exception

@Override
public SQLConnection createDatabase(ClickHouseGlobalState globalState) throws SQLException {
String host = globalState.getOptions().getHost();
int port = globalState.getOptions().getPort();
if (host == null) {
host = ClickHouseOptions.DEFAULT_HOST;
}
if (port == MainOptions.NO_SET_PORT) {
port = ClickHouseOptions.DEFAULT_PORT;
}

ClickHouseOptions clickHouseOptions = globalState.getDmbsSpecificOptions();
globalState.setClickHouseOptions(clickHouseOptions);
String url = "jdbc:clickhouse://localhost:8123/default";
String url = String.format("jdbc:clickhouse://%s:%d/default", host, port);
String databaseName = globalState.getDatabaseName();
Connection con = DriverManager.getConnection(url, globalState.getOptions().getUserName(),
globalState.getOptions().getPassword());
Expand Down
5 changes: 4 additions & 1 deletion src/sqlancer/cockroachdb/CockroachDBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
import sqlancer.common.oracle.CompositeTestOracle;
import sqlancer.common.oracle.TestOracle;

@Parameters(separators = "=", commandDescription = "Test CockroachDB")
@Parameters(separators = "=", commandDescription = "CockroachDB (default port: " + CockroachDBOptions.DEFAULT_PORT
+ " default host: " + CockroachDBOptions.DEFAULT_HOST)
public class CockroachDBOptions implements DBMSSpecificOptions<CockroachDBOracleFactory> {
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 26257;

@Parameter(names = "--oracle")
public CockroachDBOracleFactory oracle = CockroachDBOracleFactory.NOREC;
Expand Down
10 changes: 9 additions & 1 deletion src/sqlancer/cockroachdb/CockroachDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,16 @@ public void generateDatabase(CockroachDBGlobalState globalState) throws Exceptio

@Override
public SQLConnection createDatabase(CockroachDBGlobalState globalState) throws SQLException {
String host = globalState.getOptions().getHost();
int port = globalState.getOptions().getPort();
if (host == null) {
host = CockroachDBOptions.DEFAULT_HOST;
}
if (port == MainOptions.NO_SET_PORT) {
port = CockroachDBOptions.DEFAULT_PORT;
}
String databaseName = globalState.getDatabaseName();
String url = "jdbc:postgresql://localhost:26257/test";
String url = String.format("jdbc:postgresql://%s:%d/test", host, port);
Connection con = DriverManager.getConnection(url, globalState.getOptions().getUserName(),
globalState.getOptions().getPassword());
globalState.getState().logStatement("USE test");
Expand Down
5 changes: 4 additions & 1 deletion src/sqlancer/mariadb/MariaDBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import sqlancer.mariadb.MariaDBProvider.MariaDBGlobalState;
import sqlancer.mariadb.oracle.MariaDBNoRECOracle;

@Parameters
@Parameters(separators = "=", commandDescription = "MariaDB (default port: " + MariaDBOptions.DEFAULT_PORT
+ ", default host: " + MariaDBOptions.DEFAULT_HOST)
public class MariaDBOptions implements DBMSSpecificOptions<MariaDBOracleFactory> {
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 3306;

@Parameter(names = "--oracle")
public List<MariaDBOracleFactory> oracles = Arrays.asList(MariaDBOracleFactory.NOREC);
Expand Down
16 changes: 12 additions & 4 deletions src/sqlancer/mariadb/MariaDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,18 @@ public SQLConnection createDatabase(MariaDBGlobalState globalState) throws SQLEx
globalState.getState().logStatement("DROP DATABASE IF EXISTS " + globalState.getDatabaseName());
globalState.getState().logStatement("CREATE DATABASE " + globalState.getDatabaseName());
globalState.getState().logStatement("USE " + globalState.getDatabaseName());
// /?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
String url = "jdbc:mariadb://localhost:3306";
Connection con = DriverManager.getConnection(url, globalState.getOptions().getUserName(),
globalState.getOptions().getPassword());
String username = globalState.getOptions().getUserName();
String password = globalState.getOptions().getPassword();
String host = globalState.getOptions().getHost();
int port = globalState.getOptions().getPort();
if (host == null) {
host = MariaDBOptions.DEFAULT_HOST;
}
if (port == MainOptions.NO_SET_PORT) {
port = MariaDBOptions.DEFAULT_PORT;
}
String url = String.format("jdbc:mariadb://%s:%d", host, port);
Connection con = DriverManager.getConnection(url, username, password);
try (Statement s = con.createStatement()) {
s.execute("DROP DATABASE IF EXISTS " + globalState.getDatabaseName());
}
Expand Down
5 changes: 4 additions & 1 deletion src/sqlancer/mysql/MySQLOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import sqlancer.mysql.oracle.MySQLPivotedQuerySynthesisOracle;
import sqlancer.mysql.oracle.MySQLTLPWhereOracle;

@Parameters
@Parameters(separators = "=", commandDescription = "MySQL (default port: " + MySQLOptions.DEFAULT_PORT
+ ", default host: " + MySQLOptions.DEFAULT_HOST)
public class MySQLOptions implements DBMSSpecificOptions<MySQLOracleFactory> {
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 3306;

@Parameter(names = "--oracle")
public List<MySQLOracleFactory> oracles = Arrays.asList(MySQLOracleFactory.TLP_WHERE);
Expand Down
17 changes: 14 additions & 3 deletions src/sqlancer/mysql/MySQLProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import sqlancer.AbstractAction;
import sqlancer.IgnoreMeException;
import sqlancer.MainOptions;
import sqlancer.Randomly;
import sqlancer.SQLConnection;
import sqlancer.SQLProviderAdapter;
Expand Down Expand Up @@ -149,13 +150,23 @@ public void generateDatabase(MySQLGlobalState globalState) throws Exception {

@Override
public SQLConnection createDatabase(MySQLGlobalState globalState) throws SQLException {
String username = globalState.getOptions().getUserName();
String password = globalState.getOptions().getPassword();
String host = globalState.getOptions().getHost();
int port = globalState.getOptions().getPort();
if (host == null) {
host = MySQLOptions.DEFAULT_HOST;
}
if (port == MainOptions.NO_SET_PORT) {
port = MySQLOptions.DEFAULT_PORT;
}
String databaseName = globalState.getDatabaseName();
globalState.getState().logStatement("DROP DATABASE IF EXISTS " + databaseName);
globalState.getState().logStatement("CREATE DATABASE " + databaseName);
globalState.getState().logStatement("USE " + databaseName);
String url = "jdbc:mysql://localhost:3306/?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true";
Connection con = DriverManager.getConnection(url, globalState.getOptions().getUserName(),
globalState.getOptions().getPassword());
String url = String.format("jdbc:mysql://%s:%d?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true",
host, port);
Connection con = DriverManager.getConnection(url, username, password);
try (Statement s = con.createStatement()) {
s.execute("DROP DATABASE IF EXISTS " + databaseName);
}
Expand Down
8 changes: 6 additions & 2 deletions src/sqlancer/postgres/PostgresOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import sqlancer.postgres.oracle.tlp.PostgresTLPHavingOracle;
import sqlancer.postgres.oracle.tlp.PostgresTLPWhereOracle;

@Parameters
@Parameters(separators = "=", commandDescription = "PostgreSQL (default port: " + PostgresOptions.DEFAULT_PORT
+ ", default host: " + PostgresOptions.DEFAULT_HOST)
public class PostgresOptions implements DBMSSpecificOptions<PostgresOracleFactory> {
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 5432;

@Parameter(names = "--bulk-insert", description = "Specifies whether INSERT statements should be issued in bulk", arity = 1)
public boolean allowBulkInsert;
Expand All @@ -32,7 +35,8 @@ public class PostgresOptions implements DBMSSpecificOptions<PostgresOracleFactor
public boolean testCollations = true;

@Parameter(names = "--connection-url", description = "Specifies the URL for connecting to the PostgreSQL server", arity = 1)
public String connectionURL = "postgresql://localhost:5432/test";
public String connectionURL = String.format("postgresql://%s:%d/test", PostgresOptions.DEFAULT_HOST,
PostgresOptions.DEFAULT_PORT);

public enum PostgresOracleFactory implements OracleFactory<PostgresGlobalState> {
NOREC {
Expand Down
18 changes: 15 additions & 3 deletions src/sqlancer/postgres/PostgresProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import sqlancer.AbstractAction;
import sqlancer.IgnoreMeException;
import sqlancer.MainOptions;
import sqlancer.Randomly;
import sqlancer.SQLConnection;
import sqlancer.SQLProviderAdapter;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class PostgresProvider extends SQLProviderAdapter<PostgresGlobalState, Po
protected String password;
protected String entryPath;
protected String host;
protected int port;
protected String testURL;
protected String databaseName;
protected String createDatabaseCommand;
Expand Down Expand Up @@ -200,12 +202,17 @@ public SQLConnection createDatabase(PostgresGlobalState globalState) throws SQLE

username = globalState.getOptions().getUserName();
password = globalState.getOptions().getPassword();
host = globalState.getOptions().getHost();
port = globalState.getOptions().getPort();
entryPath = "/test";
entryURL = globalState.getDmbsSpecificOptions().connectionURL;
// trim URL to exclude "jdbc:"
if (entryURL.startsWith("jdbc:")) {
entryURL = entryURL.substring(5);
}
String entryDatabaseName = entryPath.substring(1);
databaseName = globalState.getDatabaseName();

try {
URI uri = new URI(entryURL);
String userInfoURI = uri.getUserInfo();
Expand All @@ -228,12 +235,16 @@ public SQLConnection createDatabase(PostgresGlobalState globalState) throws SQLE
if (pathURI != null) {
entryPath = pathURI;
}
host = uri.getHost();
if (host == null) {
host = uri.getHost();
}
if (port == MainOptions.NO_SET_PORT) {
port = uri.getPort();
}
entryURL = String.format("%s://%s:%d/%s", uri.getScheme(), host, port, entryDatabaseName);
} catch (URISyntaxException e) {
throw new AssertionError(e);
}
String entryDatabaseName = entryPath.substring(1);
databaseName = globalState.getDatabaseName();
Connection con = DriverManager.getConnection("jdbc:" + entryURL, username, password);
globalState.getState().logStatement(String.format("\\c %s;", entryDatabaseName));
globalState.getState().logStatement("DROP DATABASE IF EXISTS " + databaseName);
Expand All @@ -251,6 +262,7 @@ public SQLConnection createDatabase(PostgresGlobalState globalState) throws SQLE
String postDatabaseName = entryURL.substring(databaseIndex + entryDatabaseName.length());
testURL = preDatabaseName + databaseName + postDatabaseName;
globalState.getState().logStatement(String.format("\\c %s;", databaseName));

con = DriverManager.getConnection("jdbc:" + testURL, username, password);
return new SQLConnection(con);
}
Expand Down
5 changes: 4 additions & 1 deletion src/sqlancer/tidb/TiDBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
import sqlancer.tidb.oracle.TiDBTLPHavingOracle;
import sqlancer.tidb.oracle.TiDBTLPWhereOracle;

@Parameters
@Parameters(separators = "=", commandDescription = "TiDB (default port: " + TiDBOptions.DEFAULT_PORT
+ ", default host: " + TiDBOptions.DEFAULT_HOST)
public class TiDBOptions implements DBMSSpecificOptions<TiDBOracleFactory> {
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 4000;

@Parameter(names = "--oracle")
public List<TiDBOracleFactory> oracle = Arrays.asList(TiDBOracleFactory.QUERY_PARTITIONING);
Expand Down
12 changes: 11 additions & 1 deletion src/sqlancer/tidb/TiDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import sqlancer.AbstractAction;
import sqlancer.IgnoreMeException;
import sqlancer.MainOptions;
import sqlancer.Randomly;
import sqlancer.SQLConnection;
import sqlancer.SQLGlobalState;
Expand Down Expand Up @@ -132,8 +133,17 @@ public void generateDatabase(TiDBGlobalState globalState) throws Exception {

@Override
public SQLConnection createDatabase(TiDBGlobalState globalState) throws SQLException {
String host = globalState.getOptions().getHost();
int port = globalState.getOptions().getPort();
if (host == null) {
host = TiDBOptions.DEFAULT_HOST;
}
if (port == MainOptions.NO_SET_PORT) {
port = TiDBOptions.DEFAULT_PORT;
}

String databaseName = globalState.getDatabaseName();
String url = "jdbc:mysql://127.0.0.1:4000/";
String url = String.format("jdbc:mysql://%s:%d/", host, port);
Connection con = DriverManager.getConnection(url, globalState.getOptions().getUserName(),
globalState.getOptions().getPassword());
globalState.getState().logStatement("USE test");
Expand Down