-
Notifications
You must be signed in to change notification settings - Fork 366
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
Changes from 1 commit
b7501c7
5fac753
96f22a0
3051257
33b9ef9
fceb0ac
decb8ff
4618937
1ca57bf
7a3ebf4
03f8d6f
17e79ae
4b45629
9a5370b
f201549
dc2bc44
ba7d856
c601f4f
ddd2d02
b931c73
c520480
318272f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, the current help text and default value can be consistent here. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ public class MySQLProvider extends SQLProviderAdapter<MySQLGlobalState, MySQLOpt | |
protected String username; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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/"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
There was a problem hiding this comment.
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 likeNO_PORT_SET
and use it also in thecreateDatabase
methods?