use of com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm in project JavaSegundasQuintas by ecteruel.
the class StatementRegressionTest method testBug66430.
/**
* Tests fix for Bug#66430 - setCatalog on connection leaves ServerPreparedStatement cache for old catalog.
*
* @throws Exception
*/
@Test
public void testBug66430() throws Exception {
createDatabase("testBug66430DB1");
createTable("testBug66430DB1.testBug66430", "(id INT)");
this.stmt.executeUpdate("INSERT INTO testBug66430DB1.testBug66430 VALUES (1)");
createDatabase("testBug66430DB2");
createTable("testBug66430DB2.testBug66430", "(id INT)");
this.stmt.executeUpdate("INSERT INTO testBug66430DB2.testBug66430 VALUES (2)");
boolean useSPS = false;
boolean cachePS = false;
do {
final String testCase = String.format("Case: [useSPS: %s, cachePS: %s ]", useSPS ? "Y" : "N", cachePS ? "Y" : "N");
Properties props = new Properties();
props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), Boolean.toString(cachePS));
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
Connection testConn = getConnectionWithProps(props);
if (((JdbcConnection) testConn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA) {
testConn.setSchema("testBug66430DB1");
} else {
testConn.setCatalog("testBug66430DB1");
}
PreparedStatement testPStmt = testConn.prepareStatement("SELECT * FROM testBug66430 WHERE id > ?");
testPStmt.setInt(1, 0);
this.rs = testPStmt.executeQuery();
assertTrue(this.rs.next(), testCase);
assertEquals(1, this.rs.getInt(1), testCase);
assertFalse(this.rs.next(), testCase);
testPStmt.close();
if (((JdbcConnection) testConn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA) {
testConn.setSchema("testBug66430DB2");
} else {
testConn.setCatalog("testBug66430DB2");
}
testPStmt = testConn.prepareStatement("SELECT * FROM testBug66430 WHERE id > ?");
testPStmt.setInt(1, 0);
this.rs = testPStmt.executeQuery();
assertTrue(this.rs.next(), testCase);
assertEquals(2, this.rs.getInt(1), testCase);
assertFalse(this.rs.next(), testCase);
testPStmt.close();
// Do it again to make sure cached prepared statements behave correctly.
if (((JdbcConnection) testConn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA) {
testConn.setSchema("testBug66430DB1");
} else {
testConn.setCatalog("testBug66430DB1");
}
testPStmt = testConn.prepareStatement("SELECT * FROM testBug66430 WHERE id > ?");
testPStmt.setInt(1, 0);
this.rs = testPStmt.executeQuery();
assertTrue(this.rs.next(), testCase);
assertEquals(1, this.rs.getInt(1), testCase);
assertFalse(this.rs.next(), testCase);
testPStmt.close();
if (((JdbcConnection) testConn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA) {
testConn.setSchema("testBug66430DB2");
} else {
testConn.setCatalog("testBug66430DB2");
}
testPStmt = testConn.prepareStatement("SELECT * FROM testBug66430 WHERE id > ?");
testPStmt.setInt(1, 0);
this.rs = testPStmt.executeQuery();
assertTrue(this.rs.next(), testCase);
assertEquals(2, this.rs.getInt(1), testCase);
assertFalse(this.rs.next(), testCase);
testPStmt.close();
testConn.close();
} while ((useSPS = !useSPS) || (cachePS = !cachePS));
}
use of com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm in project JavaSegundasQuintas by ecteruel.
the class MetaDataRegressionTest method testBug61332.
/**
* Tests fix for BUG#61332 - Check if "LIKE" or "=" is sent to server in I__S query when no wildcards are supplied for schema parameter.
*
* @throws Exception
*/
@Test
public void testBug61332() throws Exception {
Properties props = new Properties();
props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.useInformationSchema.getKeyName(), "true");
props.setProperty(PropertyKey.queryInterceptors.getKeyName(), QueryInterceptorBug61332.class.getName());
createDatabase("dbbug61332");
Connection testConn = getConnectionWithProps(props);
try {
createTable("dbbug61332.bug61332", "(c1 char(1))");
DatabaseMetaData metaData = testConn.getMetaData();
this.rs = ((JdbcConnection) this.conn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA ? metaData.getColumns(null, "dbbug61332", "bug61332", null) : metaData.getColumns("dbbug61332", null, "bug61332", null);
this.rs.next();
} finally {
}
}
use of com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm in project JavaSegundasQuintas by ecteruel.
the class MetaDataRegressionTest method checkGetProceduresForBug69298.
private void checkGetProceduresForBug69298(String stepDescription, Connection testConn) throws Exception {
DatabaseMetaData testDbMetaData = testConn.getMetaData();
boolean dbMapsToSchema = ((JdbcConnection) testConn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA;
ResultSet proceduresMD = testDbMetaData.getProcedures(null, null, "testBug69298_%");
String sd = stepDescription + " getProcedures() ";
boolean isGetProceduresReturnsFunctions = ((JdbcConnection) testConn).getPropertySet().getBooleanProperty(PropertyKey.getProceduresReturnsFunctions).getValue();
if (isGetProceduresReturnsFunctions) {
assertTrue(proceduresMD.next(), sd + "1st of 2 rows expected.");
// function: testBug69298_func
assertEquals(dbMapsToSchema ? "def" : testConn.getCatalog(), proceduresMD.getString("PROCEDURE_CAT"), sd + "-> PROCEDURE_CAT");
assertEquals(dbMapsToSchema ? testConn.getSchema() : null, proceduresMD.getString("PROCEDURE_SCHEM"), sd + "-> PROCEDURE_SCHEM");
assertEquals("testBug69298_func", proceduresMD.getString("PROCEDURE_NAME"), sd + "-> PROCEDURE_NAME");
assertEquals("testBug69298_func comment", proceduresMD.getString("REMARKS"), sd + "-> REMARKS");
assertEquals(DatabaseMetaData.procedureReturnsResult, proceduresMD.getShort("PROCEDURE_TYPE"), sd + "-> PROCEDURE_TYPE");
assertEquals("testBug69298_func", proceduresMD.getString("SPECIFIC_NAME"), sd + "-> SPECIFIC_NAME");
assertTrue(proceduresMD.next(), sd + "2nd of 2 rows expected.");
} else {
assertTrue(proceduresMD.next(), sd + "one row expected.");
}
// procedure: testBug69298_proc
assertEquals(dbMapsToSchema ? "def" : testConn.getCatalog(), proceduresMD.getString("PROCEDURE_CAT"), sd + "-> PROCEDURE_CAT");
assertEquals(dbMapsToSchema ? testConn.getSchema() : null, proceduresMD.getString("PROCEDURE_SCHEM"), sd + "-> PROCEDURE_SCHEM");
assertEquals("testBug69298_proc", proceduresMD.getString("PROCEDURE_NAME"), sd + "-> PROCEDURE_NAME");
assertEquals("testBug69298_proc comment", proceduresMD.getString("REMARKS"), sd + "-> REMARKS");
assertEquals(DatabaseMetaData.procedureNoResult, proceduresMD.getShort("PROCEDURE_TYPE"), sd + "-> PROCEDURE_TYPE");
assertEquals("testBug69298_proc", proceduresMD.getString("SPECIFIC_NAME"), sd + "-> SPECIFIC_NAME");
assertFalse(proceduresMD.next(), stepDescription + "no more rows expected.");
}
use of com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm in project JavaSegundasQuintas by ecteruel.
the class MetaDataRegressionTest method testBug20504139.
/**
* Tests fix for BUG#20504139 - GETFUNCTIONCOLUMNS() AND GETPROCEDURECOLUMNS() RETURNS ERROR FOR VALID INPUTS.
*
* @throws Exception
*/
@Test
public void testBug20504139() throws Exception {
createFunction("testBug20504139f", "(namef CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT('Hello, ', namef, '!')");
createFunction("`testBug20504139``f`", "(namef CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT('Hello, ', namef, '!')");
createProcedure("testBug20504139p", "(INOUT namep CHAR(50)) SELECT CONCAT('Hello, ', namep, '!') INTO namep");
createProcedure("`testBug20504139``p`", "(INOUT namep CHAR(50)) SELECT CONCAT('Hello, ', namep, '!') INTO namep");
for (int testCase = 0; testCase < 8; testCase++) {
// 3 props, 8 combinations: 2^3 = 8
boolean usePedantic = (testCase & 1) == 1;
boolean useInformationSchema = (testCase & 2) == 2;
boolean useFuncsInProcs = (testCase & 4) == 4;
String connProps = String.format("pedantic=%s,useInformationSchema=%s,getProceduresReturnsFunctions=%s", usePedantic, useInformationSchema, useFuncsInProcs);
System.out.printf("testBug20504139_%d: %s%n", testCase, connProps);
Properties props = new Properties();
props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.pedantic.getKeyName(), "" + usePedantic);
props.setProperty(PropertyKey.useInformationSchema.getKeyName(), "" + useInformationSchema);
props.setProperty(PropertyKey.getProceduresReturnsFunctions.getKeyName(), "" + useFuncsInProcs);
Connection testConn = getConnectionWithProps(props);
DatabaseMetaData dbmd = testConn.getMetaData();
boolean dbMapsToSchema = ((JdbcConnection) testConn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA;
ResultSet testRs = null;
try {
/*
* test DatabaseMetadata.getProcedureColumns for function
*/
int i = 1;
try {
for (String name : new String[] { "testBug20504139f", "testBug20504139`f" }) {
testRs = dbMapsToSchema ? dbmd.getProcedureColumns("", this.dbName, name, "%") : dbmd.getProcedureColumns(this.dbName, "", name, "%");
if (useFuncsInProcs) {
assertTrue(testRs.next());
assertEquals("", testRs.getString(4), testCase + "." + i + ". expected function column name (empty)");
assertEquals(DatabaseMetaData.procedureColumnReturn, testRs.getInt(5), testCase + "." + i + ". expected function column type (empty)");
assertTrue(testRs.next());
assertEquals("namef", testRs.getString(4), testCase + "." + i + ". expected function column name");
assertEquals(DatabaseMetaData.procedureColumnIn, testRs.getInt(5), testCase + "." + i + ". expected function column type (empty)");
assertFalse(testRs.next());
} else {
assertFalse(testRs.next());
}
testRs.close();
i++;
}
} catch (SQLException e) {
assertFalse(e.getMessage().matches("FUNCTION `testBug20504139(:?`{2})?[fp]` does not exist"), testCase + "." + i + ". failed to retrieve function columns, with getProcedureColumns(), from database meta data.");
throw e;
}
/*
* test DatabaseMetadata.getProcedureColumns for procedure
*/
i = 1;
try {
for (String name : new String[] { "testBug20504139p", "testBug20504139`p" }) {
testRs = dbMapsToSchema ? dbmd.getProcedureColumns("", this.dbName, name, "%") : dbmd.getProcedureColumns(this.dbName, "", name, "%");
assertTrue(testRs.next());
assertEquals("namep", testRs.getString(4), testCase + ". expected procedure column name");
assertEquals(DatabaseMetaData.procedureColumnInOut, testRs.getInt(5), testCase + ". expected procedure column type (empty)");
assertFalse(testRs.next());
testRs.close();
i++;
}
} catch (SQLException e) {
assertFalse(e.getMessage().matches("PROCEDURE `testBug20504139(:?`{2})?[fp]` does not exist"), testCase + "." + i + ". failed to retrieve prodedure columns, with getProcedureColumns(), from database meta data.");
throw e;
}
/*
* test DatabaseMetadata.getFunctionColumns for function
*/
i = 1;
try {
for (String name : new String[] { "testBug20504139f", "testBug20504139`f" }) {
testRs = dbMapsToSchema ? dbmd.getFunctionColumns("", this.dbName, name, "%") : dbmd.getFunctionColumns(this.dbName, "", name, "%");
assertTrue(testRs.next());
assertEquals("", testRs.getString(4), testCase + ". expected function column name (empty)");
assertEquals(DatabaseMetaData.functionReturn, testRs.getInt(5), testCase + ". expected function column type (empty)");
assertTrue(testRs.next());
assertEquals("namef", testRs.getString(4), testCase + ". expected function column name");
assertEquals(DatabaseMetaData.functionColumnIn, testRs.getInt(5), testCase + ". expected function column type (empty)");
assertFalse(testRs.next());
testRs.close();
i++;
}
} catch (SQLException e) {
assertFalse(e.getMessage().matches("FUNCTION `testBug20504139(:?`{2})?[fp]` does not exist"), testCase + "." + i + ". failed to retrieve function columns, with getFunctionColumns(), from database meta data.");
throw e;
}
/*
* test DatabaseMetadata.getFunctionColumns for procedure
*/
i = 1;
try {
for (String name : new String[] { "testBug20504139p", "testBug20504139`p" }) {
testRs = dbMapsToSchema ? dbmd.getFunctionColumns("", this.dbName, name, "%") : dbmd.getFunctionColumns(this.dbName, "", name, "%");
assertFalse(testRs.next());
testRs.close();
i++;
}
} catch (SQLException e) {
assertFalse(e.getMessage().matches("PROCEDURE `testBug20504139(:?`{2})?[fp]` does not exist"), testCase + "." + i + ". failed to retrieve procedure columns, with getFunctionColumns(), from database meta data.");
throw e;
}
} finally {
testConn.close();
}
}
}
use of com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm in project JavaSegundasQuintas by ecteruel.
the class MetaDataRegressionTest method testBug69290.
/**
* Tests fix for BUG#69290 - JDBC Table type "SYSTEM TABLE" is used inconsistently.
*
* Tests DatabaseMetaData.getTableTypes() and DatabaseMetaData.getTables() against schemas: mysql, information_schema, performance_schema, test.
*
* @throws Exception
*/
@Test
public void testBug69290() throws Exception {
String[] testStepDescription = new String[] { "MySQL MetaData", "I__S MetaData" };
Properties props = new Properties();
props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.useInformationSchema.getKeyName(), "true");
Connection connUseIS = getConnectionWithProps(props);
props.setProperty(PropertyKey.nullDatabaseMeansCurrent.getKeyName(), "false");
Connection connUseISAndNullAll = getConnectionWithProps(props);
props.remove(PropertyKey.useInformationSchema.getKeyName());
Connection connNullAll = getConnectionWithProps(props);
boolean dbMapsToSchema = ((JdbcConnection) this.conn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA;
final String testDb = dbMapsToSchema ? this.conn.getSchema() : this.conn.getCatalog();
Connection[] testConnections = new Connection[] { this.conn, connUseIS };
// check table types returned in getTableTypes()
final List<String> tableTypes = Arrays.asList(new String[] { "LOCAL TEMPORARY", "SYSTEM TABLE", "SYSTEM VIEW", "TABLE", "VIEW" });
for (int i = 0; i < testStepDescription.length; i++) {
DatabaseMetaData testDbMetaData = testConnections[i].getMetaData();
this.rs = testDbMetaData.getTableTypes();
int idx = 0;
while (this.rs.next()) {
String message = testStepDescription[i] + ", table type '" + this.rs.getString("TABLE_TYPE") + "'";
assertFalse(idx >= tableTypes.size(), message + " not expected.");
assertEquals(tableTypes.get(idx++), this.rs.getString("TABLE_TYPE"), message);
}
}
// create table and view in '(test)' schema
createTable("testBug69290_table", "(c1 INT)");
createView("testBug69290_view", "AS SELECT * FROM testBug69290_table WHERE c1 > 1");
int[][] countResults = new int[][] { { 0, 0, 0 }, { 0, 0, 0 } };
// check table types returned in getTables() for each catalog/schema
for (int i = 0; i < testStepDescription.length; i++) {
DatabaseMetaData testDbMetaData = testConnections[i].getMetaData();
// check catalog/schema 'information_schema'
this.rs = dbMapsToSchema ? testDbMetaData.getTables(null, "information_schema", "%", null) : testDbMetaData.getTables("information_schema", null, "%", null);
while (this.rs.next()) {
assertEquals("SYSTEM VIEW", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", 'information_schema' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
countResults[i][0]++;
}
// check catalog/schema 'mysql'
this.rs = dbMapsToSchema ? testDbMetaData.getTables(null, "mysql", "%", null) : testDbMetaData.getTables("mysql", null, "%", null);
while (this.rs.next()) {
assertEquals("SYSTEM TABLE", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", 'mysql' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
countResults[i][1]++;
}
// check catalog/schema 'performance_schema'
this.rs = dbMapsToSchema ? testDbMetaData.getTables(null, "performance_schema", "%", null) : testDbMetaData.getTables("performance_schema", null, "%", null);
while (this.rs.next()) {
assertEquals("SYSTEM TABLE", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", 'performance_schema' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
countResults[i][2]++;
}
// check catalog/schema '(test)'
this.rs = dbMapsToSchema ? testDbMetaData.getTables(null, testDb, "testBug69290_%", null) : testDbMetaData.getTables(testDb, null, "testBug69290_%", null);
assertTrue(this.rs.next(), testStepDescription[i] + ", '" + testDb + "' catalog/schema, expected row from getTables().");
assertEquals("TABLE", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", '" + testDb + "' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
assertTrue(this.rs.next(), testStepDescription[i] + ", '" + testDb + "' catalog/schema, expected row from getTables().");
assertEquals("VIEW", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", '" + testDb + "' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
}
// compare results count
assertTrue(countResults[0][0] == countResults[1][0], "The number of results from getTables() MySQl(" + countResults[0][0] + ") and I__S(" + countResults[1][0] + ") should be the same for 'information_schema' catalog/schema.");
assertTrue(countResults[0][1] == countResults[1][1], "The number of results from getTables() MySQl(" + countResults[0][1] + ") and I__S(" + countResults[1][1] + ") should be the same for 'mysql' catalog/schema.");
assertTrue(countResults[0][2] == countResults[1][2], "The number of results from getTables() MySQl(" + countResults[0][2] + ") and I__S(" + countResults[1][2] + ") should be the same for 'performance_schema' catalog/schema.");
testConnections = new Connection[] { connNullAll, connUseISAndNullAll };
countResults = new int[][] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
// check table types returned in getTables() for all catalogs/schemas and filter by table type (tested with property nullCatalogMeansCurrent=false)
for (int i = 0; i < testStepDescription.length; i++) {
DatabaseMetaData testDbMetaData = testConnections[i].getMetaData();
int j = 0;
// check table type filters
for (String tableType : tableTypes) {
this.rs = testDbMetaData.getTables(null, null, "%", new String[] { tableType });
while (this.rs.next()) {
assertEquals(tableType, this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", table type filter '" + tableType + "', wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
countResults[i][j]++;
}
j++;
}
}
// compare results count
int i = 0;
for (String tableType : tableTypes) {
assertTrue(countResults[0][i] == countResults[1][i], "The number of results from getTables() MySQl(" + countResults[0][i] + ") and I__S(" + countResults[1][i] + ") should be the same for '" + tableType + "' table type filter.");
i++;
}
}
Aggregations