Skip to content

Fix#95: support host and port arguments configuration for different DBMSs in SQLancer #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
adding the help text and modifing the default values of host and port
  • Loading branch information
abcdabcd3899 committed Mar 20, 2021
commit 4b4562996d152ff17d9443eac2b77faaa7796e8b
6 changes: 3 additions & 3 deletions src/sqlancer/MainOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public class MainOptions {
private String password = "sqlancer"; // NOPMD

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

@Parameter(names = "--port", description = "The port used to log into the DBMS")
private String port = "sqlancer"; // NOPMD
private int port = -1; // NOPMD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than checking for -1, could you please introduce a constant like NO_PORT_SET and use it also in the createDatabase methods?


@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 @@ -161,7 +161,7 @@ public String getHost() {
return host;
}

public String getPort() {
public int getPort() {
return port;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sqlancer/clickhouse/ClickHouseOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import sqlancer.clickhouse.oracle.tlp.ClickHouseTLPWhereOracle;
import sqlancer.common.oracle.TestOracle;

@Parameters(separators = "=", commandDescription = "ClickHouse")
@Parameters(separators = "=", commandDescription = "ClickHouse (default port: 8123, default host: localhost)")
public class ClickHouseOptions implements DBMSSpecificOptions<ClickHouseOracleFactory> {

@Parameter(names = "--oracle")
Expand Down
10 changes: 5 additions & 5 deletions src/sqlancer/clickhouse/ClickHouseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class ClickHouseProvider extends SQLProviderAdapter<ClickHouseGlobalState, ClickHouseOptions> {
protected String host;
protected String port;
protected int port;

public ClickHouseProvider() {
super(ClickHouseGlobalState.class, ClickHouseOptions.class);
Expand Down Expand Up @@ -106,17 +106,17 @@ public void generateDatabase(ClickHouseGlobalState globalState) throws Exception
public SQLConnection createDatabase(ClickHouseGlobalState globalState) throws SQLException {
host = globalState.getOptions().getHost();
port = globalState.getOptions().getPort();
if ("sqlancer".equals(host)) {
if (host == null) {
host = "localhost";
}
if ("sqlancer".equals(port)) {
port = "8123";
if (port == -1) {
port = 8123;
}

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

@Parameters(separators = "=", commandDescription = "Test CockroachDB")
@Parameters(separators = "=", commandDescription = "CockroachDB (default port: 26257, default host: localhost)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than hard-coding the port and localhost, could you please introduce constants for them that you use in both the description and when setting the values?

For example, in CockroachDBOptions you can have a field final static int DEFAULT_PORT = 26257; and reference it both here as "CockroachDB (default port: " + CockroachDBOptions.DEFAULT_PORT + ... and below in createDatabase. By doing so, the help text and actual default values will always be consistent.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the current help text and default value can be consistent here.
Thank you for your suggestions.
TBR @mrigger

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry again for the late response - I had some full-day obligations in the last couple of days, and will be able to respond much faster in the future.

Why does using the constant in the annotation text not work?

public class CockroachDBOptions implements DBMSSpecificOptions<CockroachDBOracleFactory> {

@Parameter(names = "--oracle")
Expand Down
10 changes: 5 additions & 5 deletions src/sqlancer/cockroachdb/CockroachDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class CockroachDBProvider extends SQLProviderAdapter<CockroachDBGlobalState, CockroachDBOptions> {
protected String host;
protected String port;
protected int port;

public CockroachDBProvider() {
super(CockroachDBGlobalState.class, CockroachDBOptions.class);
Expand Down Expand Up @@ -252,16 +252,16 @@ public void generateDatabase(CockroachDBGlobalState globalState) throws Exceptio
public SQLConnection createDatabase(CockroachDBGlobalState globalState) throws SQLException {
host = globalState.getOptions().getHost();
port = globalState.getOptions().getPort();
if ("sqlancer".equals(host)) {
if (host == null) {
host = "localhost";
}
if ("sqlancer".equals(port)) {
port = "26257";
if (port == -1) {
port = 26257;
}
String databaseName = globalState.getDatabaseName();
// String url = "jdbc:postgresql://localhost:26257/test";
// String url = "jdbc:postgresql://" + host + ":" + port + "/test";
String url = String.format("jdbc:postgresql://%s:%s/test", host, port);
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
2 changes: 1 addition & 1 deletion src/sqlancer/mariadb/MariaDBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import sqlancer.mariadb.MariaDBProvider.MariaDBGlobalState;
import sqlancer.mariadb.oracle.MariaDBNoRECOracle;

@Parameters
@Parameters(separators = "=", commandDescription = "MariaDB (default port: 3306, default host: localhost)")
public class MariaDBOptions implements DBMSSpecificOptions<MariaDBOracleFactory> {

@Parameter(names = "--oracle")
Expand Down
10 changes: 5 additions & 5 deletions src/sqlancer/mariadb/MariaDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MariaDBProvider extends SQLProviderAdapter<MariaDBGlobalState, Mari
protected String username;
protected String password;
protected String host;
protected String port;
protected int port;

public MariaDBProvider() {
super(MariaDBGlobalState.class, MariaDBOptions.class);
Expand Down Expand Up @@ -177,14 +177,14 @@ public SQLConnection createDatabase(MariaDBGlobalState globalState) throws SQLEx
password = globalState.getOptions().getPassword();
host = globalState.getOptions().getHost();
port = globalState.getOptions().getPort();
if ("sqlancer".equals(host)) {
if (host == null) {
host = "localhost";
}
if ("sqlancer".equals(port)) {
port = "3306";
if (port == -1) {
port = 3306;
}
// String url = "jdbc:mariadb://" + host + ":" + port;
String url = String.format("jdbc:mariadb://%s:%s", host, 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
2 changes: 1 addition & 1 deletion src/sqlancer/mysql/MySQLOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import sqlancer.mysql.oracle.MySQLPivotedQuerySynthesisOracle;
import sqlancer.mysql.oracle.MySQLTLPWhereOracle;

@Parameters
@Parameters(separators = "=", commandDescription = "MySQL (default port: 3306, default host: localhost)")
public class MySQLOptions implements DBMSSpecificOptions<MySQLOracleFactory> {

@Parameter(names = "--oracle")
Expand Down
10 changes: 5 additions & 5 deletions src/sqlancer/mysql/MySQLProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MySQLProvider extends SQLProviderAdapter<MySQLGlobalState, MySQLOpt
protected String username;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these (and equivalent variables in other classes) fields and not local variables? They are only used in the createDatabase method, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not really understand. Could you expand on what issues there might be when using a local variable rather than a field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we would still use local variables here, but if you are reluctant to do this for this PR, I can also do this in a future follow-up PR.

protected String password;
protected String host;
protected String port;
protected int port;

public MySQLProvider() {
super(MySQLGlobalState.class, MySQLOptions.class);
Expand Down Expand Up @@ -157,19 +157,19 @@ public SQLConnection createDatabase(MySQLGlobalState globalState) throws SQLExce
password = globalState.getOptions().getPassword();
host = globalState.getOptions().getHost();
port = globalState.getOptions().getPort();
if ("sqlancer".equals(host)) {
if (host == null) {
host = "localhost";
}
if ("sqlancer".equals(port)) {
port = "3306";
if (port == -1) {
port = 3306;
}
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://" + host + ":" + port
// + "?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true";
String url = String.format("jdbc:mysql://%s:%s?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true",
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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/sqlancer/postgres/PostgresOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import sqlancer.postgres.oracle.tlp.PostgresTLPHavingOracle;
import sqlancer.postgres.oracle.tlp.PostgresTLPWhereOracle;

@Parameters
@Parameters(separators = "=", commandDescription = "PostgreSQL (default port: 5432, default host: localhost)")
public class PostgresOptions implements DBMSSpecificOptions<PostgresOracleFactory> {

@Parameter(names = "--bulk-insert", description = "Specifies whether INSERT statements should be issued in bulk", arity = 1)
Expand Down
10 changes: 5 additions & 5 deletions src/sqlancer/postgres/PostgresProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class PostgresProvider extends SQLProviderAdapter<PostgresGlobalState, Po
protected String password;
protected String entryPath;
protected String host;
protected String port;
protected int port;
protected String testURL;
protected String databaseName;
protected String createDatabaseCommand;
Expand Down Expand Up @@ -234,13 +234,13 @@ public SQLConnection createDatabase(PostgresGlobalState globalState) throws SQLE
if (pathURI != null) {
entryPath = pathURI;
}
if ("sqlancer".equals(host)) {
if (host == null) {
host = uri.getHost();
}
if ("sqlancer".equals(port)) {
port = Integer.toString(uri.getPort());
if (port == -1) {
port = uri.getPort();
}
entryURL = String.format("%s://%s:%s/%s", uri.getScheme(), host, port, entryDatabaseName);
entryURL = String.format("%s://%s:%d/%s", uri.getScheme(), host, port, entryDatabaseName);
} catch (URISyntaxException e) {
throw new AssertionError(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sqlancer/tidb/TiDBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sqlancer.tidb.oracle.TiDBTLPHavingOracle;
import sqlancer.tidb.oracle.TiDBTLPWhereOracle;

@Parameters
@Parameters(separators = "=", commandDescription = "PostgreSQL (default port: 4000, default host: localhost)")
public class TiDBOptions implements DBMSSpecificOptions<TiDBOracleFactory> {

@Parameter(names = "--oracle")
Expand Down
10 changes: 5 additions & 5 deletions src/sqlancer/tidb/TiDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class TiDBProvider extends SQLProviderAdapter<TiDBGlobalState, TiDBOptions> {
protected String host;
protected String port;
protected int port;

public TiDBProvider() {
super(TiDBGlobalState.class, TiDBOptions.class);
Expand Down Expand Up @@ -136,17 +136,17 @@ public void generateDatabase(TiDBGlobalState globalState) throws Exception {
public SQLConnection createDatabase(TiDBGlobalState globalState) throws SQLException {
host = globalState.getOptions().getHost();
port = globalState.getOptions().getPort();
if ("sqlancer".equals(host)) {
if (host == null) {
host = "localhost";
}
if ("sqlancer".equals(port)) {
port = "4000";
if (port == -1) {
port = 4000;
}

String databaseName = globalState.getDatabaseName();
// String url = "jdbc:mysql://127.0.0.1:4000/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we could remove the commented-out code (but you don't need to do this for this PR).

// String url = "jdbc:mysql://" + host + ":" + port + "/";
String url = String.format("jdbc:mysql://%s:%s/", host, port);
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy