Skip to content

Commit

Permalink
Merge pull request #7257 from dolthub/fulghum/dolt-7247
Browse files Browse the repository at this point in the history
Update MySQL Connector/J integration tests to cover table-qualified field lookups
  • Loading branch information
fulghum authored Jan 5, 2024
2 parents e2c0698 + 4b585b2 commit 58c82fa
Showing 1 changed file with 73 additions and 43 deletions.
116 changes: 73 additions & 43 deletions integration-tests/mysql-client-tests/java/MySQLConnectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,64 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

public class MySQLConnectorTest {

// test queries to be run against Dolt
private static final String[] queries = {
"create table test (pk int, `value` int, primary key(pk))",
"describe test",
"select * from test",
"insert into test (pk, `value`) values (0,0)",
"select * from test",
"call dolt_add('-A')",
"call dolt_commit('-m', 'my commit')",
"select COUNT(*) FROM dolt_log",
"call dolt_checkout('-b', 'mybranch')",
"insert into test (pk, `value`) values (1,1)",
"call dolt_commit('-a', '-m', 'my commit2')",
"call dolt_checkout('main')",
"call dolt_merge('mybranch')",
"select COUNT(*) FROM dolt_log",
};

// We currently only test a single field value in the first row
private static final String[] expectedResults = {
"0",
"pk",
null,
"1",
"0",
"0",
"0",
"2",
"0",
"1",
"1",
"0",
"",
"3"
};

// fieldAccessors are the value used to access a field in a row in a result set. Currently, only
// String (i.e column name) and Integer (i.e. field position) values are supported.
private static final Object[] fieldAccessors = {
1,
1,
"pk",
1,
"test.pk",
1,
1,
1,
1,
1,
1,
1,
1,
"COUNT(*)",
};

public static void main(String[] args) {
Connection conn = null;

Expand All @@ -14,54 +70,28 @@ public static void main(String[] args) {

try {
String url = "jdbc:mysql://127.0.0.1:" + port + "/" + db;
String password = "";

conn = DriverManager.getConnection(url, user, password);

Statement st = conn.createStatement();
String password = "";

String[] queries = {
"create table test (pk int, `value` int, primary key(pk))",
"describe test",
"select * from test",
"insert into test (pk, `value`) values (0,0)",
"select * from test",
"call dolt_add('-A')",
"call dolt_commit('-m', 'my commit')",
"select COUNT(*) FROM dolt_log",
"call dolt_checkout('-b', 'mybranch')",
"insert into test (pk, `value`) values (1,1)",
"call dolt_commit('-a', '-m', 'my commit2')",
"call dolt_checkout('main')",
"call dolt_merge('mybranch')",
"select COUNT(*) FROM dolt_log",
};

// Only test the first row, column pair for now
String[] results = {
"0",
"pk",
null,
"1",
"0",
"0",
"0",
"2",
"0",
"1",
"1",
"0",
"",
"3"
};
conn = DriverManager.getConnection(url, user, password);
Statement st = conn.createStatement();

for (int i = 0; i < queries.length; i++) {
String query = queries[i];
String expected = results[i];
String expected = expectedResults[i];
if ( st.execute(query) ) {
ResultSet rs = st.getResultSet();
if (rs.next()) {
String result = rs.getString(1);
String result = "";
Object fieldAccessor = fieldAccessors[i];
if (fieldAccessor instanceof String) {
result = rs.getString((String)fieldAccessor);
} else if (fieldAccessor instanceof Integer) {
result = rs.getString((Integer)fieldAccessor);
} else {
System.out.println("Unsupported field accessor value: " + fieldAccessor);
System.exit(1);
}

if (!expected.equals(result) && !(query.contains("dolt_commit")) && !(query.contains("dolt_merge"))) {
System.out.println("Query: \n" + query);
System.out.println("Expected:\n" + expected);
Expand All @@ -83,7 +113,7 @@ public static void main(String[] args) {
} catch (SQLException ex) {
System.out.println("An error occurred.");
ex.printStackTrace();
System.exit(1);
System.exit(1);
}
}
}

0 comments on commit 58c82fa

Please sign in to comment.