Search in sources :

Example 1 with StatementsTest

use of testsuite.simple.StatementsTest in project JavaSegundasQuintas by ecteruel.

the class StatementRegressionTest method testBug103612.

/**
 * Test fix for Bug#103612 (32902019), Incorrectly identified WITH...SELECT as unsafe for read-only connections.
 *
 * @throws Exception
 *
 * @see StatementsTest#testReadOnlySafeStatements()
 */
@Test
public void testBug103612() throws Exception {
    assumeTrue(versionMeetsMinimum(8, 0, 1), "MySQL 8.0.1+ is required to run this test.");
    createTable("testBug103612", "(id INT)");
    String query = "WITH cte AS (SELECT * FROM testBug103612) SELECT * FROM cte";
    boolean useSPS = false;
    boolean readOnly = false;
    do {
        final String testCase = String.format("Case [SPS: %s, ReadOnly: %s]", useSPS ? "Y" : "N", readOnly ? "Y" : "N");
        Properties props = new Properties();
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        Connection testConn = getConnectionWithProps(props);
        testConn.setReadOnly(readOnly);
        try (Statement testStmt = testConn.createStatement()) {
            assertTrue(testStmt.execute(query), testCase);
        }
        try (PreparedStatement testPstmt = testConn.prepareStatement(query)) {
            assertTrue(testPstmt.execute(), testCase);
        }
        testConn.close();
    } while ((useSPS = !useSPS) || (readOnly = !readOnly));
}
Also used : JdbcStatement(com.mysql.cj.jdbc.JdbcStatement) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Properties(java.util.Properties) StatementsTest(testsuite.simple.StatementsTest) Test(org.junit.jupiter.api.Test)

Example 2 with StatementsTest

use of testsuite.simple.StatementsTest in project ABC by RuiPinto96274.

the class StatementRegressionTest method testBug103612.

/**
 * Test fix for Bug#103612 (32902019), Incorrectly identified WITH...SELECT as unsafe for read-only connections.
 *
 * @throws Exception
 *
 * @see StatementsTest#testReadOnlySafeStatements()
 */
@Test
public void testBug103612() throws Exception {
    assumeTrue(versionMeetsMinimum(8, 0, 1), "MySQL 8.0.1+ is required to run this test.");
    createTable("testBug103612", "(id INT)");
    String query = "WITH cte AS (SELECT * FROM testBug103612) SELECT * FROM cte";
    boolean useSPS = false;
    boolean readOnly = false;
    do {
        final String testCase = String.format("Case [SPS: %s, ReadOnly: %s]", useSPS ? "Y" : "N", readOnly ? "Y" : "N");
        Properties props = new Properties();
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        Connection testConn = getConnectionWithProps(props);
        testConn.setReadOnly(readOnly);
        try (Statement testStmt = testConn.createStatement()) {
            assertTrue(testStmt.execute(query), testCase);
        }
        try (PreparedStatement testPstmt = testConn.prepareStatement(query)) {
            assertTrue(testPstmt.execute(), testCase);
        }
        testConn.close();
    } while ((useSPS = !useSPS) || (readOnly = !readOnly));
}
Also used : JdbcStatement(com.mysql.cj.jdbc.JdbcStatement) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Properties(java.util.Properties) StatementsTest(testsuite.simple.StatementsTest) Test(org.junit.jupiter.api.Test)

Example 3 with StatementsTest

use of testsuite.simple.StatementsTest in project aws-mysql-jdbc by awslabs.

the class StatementRegressionTest method testBug103612.

/**
 * Test fix for Bug#103612 (32902019), Incorrectly identified WITH...SELECT as unsafe for read-only connections.
 *
 * @throws Exception
 *
 * @see StatementsTest#testReadOnlySafeStatements()
 */
@Test
public void testBug103612() throws Exception {
    assumeTrue(versionMeetsMinimum(8, 0, 1), "MySQL 8.0.1+ is required to run this test.");
    createTable("testBug103612", "(id INT)");
    String query = "WITH cte AS (SELECT * FROM testBug103612) SELECT * FROM cte";
    boolean useSPS = false;
    boolean readOnly = false;
    do {
        final String testCase = String.format("Case [SPS: %s, ReadOnly: %s]", useSPS ? "Y" : "N", readOnly ? "Y" : "N");
        Properties props = new Properties();
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        Connection testConn = getConnectionWithProps(props);
        testConn.setReadOnly(readOnly);
        try (Statement testStmt = testConn.createStatement()) {
            assertTrue(testStmt.execute(query), testCase);
        }
        try (PreparedStatement testPstmt = testConn.prepareStatement(query)) {
            assertTrue(testPstmt.execute(), testCase);
        }
        testConn.close();
    } while ((useSPS = !useSPS) || (readOnly = !readOnly));
}
Also used : JdbcStatement(com.mysql.cj.jdbc.JdbcStatement) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Properties(java.util.Properties) StatementsTest(testsuite.simple.StatementsTest) Test(org.junit.jupiter.api.Test)

Aggregations

MysqlConnection (com.mysql.cj.MysqlConnection)3 ClientPreparedStatement (com.mysql.cj.jdbc.ClientPreparedStatement)3 JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)3 JdbcPreparedStatement (com.mysql.cj.jdbc.JdbcPreparedStatement)3 JdbcStatement (com.mysql.cj.jdbc.JdbcStatement)3 ServerPreparedStatement (com.mysql.cj.jdbc.ServerPreparedStatement)3 ReplicationConnection (com.mysql.cj.jdbc.ha.ReplicationConnection)3 CallableStatement (java.sql.CallableStatement)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 Statement (java.sql.Statement)3 Properties (java.util.Properties)3 XAConnection (javax.sql.XAConnection)3 Test (org.junit.jupiter.api.Test)3 StatementsTest (testsuite.simple.StatementsTest)3