Search in sources :

Example 1 with ResultSetImpl

use of com.mysql.cj.jdbc.result.ResultSetImpl in project aws-mysql-jdbc by awslabs.

the class CallableStatement method getObject.

@Override
public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        ResultSetInternalMethods rs = getOutputParameters(parameterIndex);
        // remove cast once 1.5, 1.6 EOL'd
        T retVal = ((ResultSetImpl) rs).getObject(mapOutputParameterIndexToRsIndex(parameterIndex), type);
        this.outputParamWasNull = rs.wasNull();
        return retVal;
    }
}
Also used : ResultSetInternalMethods(com.mysql.cj.jdbc.result.ResultSetInternalMethods) ResultSetImpl(com.mysql.cj.jdbc.result.ResultSetImpl)

Example 2 with ResultSetImpl

use of com.mysql.cj.jdbc.result.ResultSetImpl in project aws-mysql-jdbc by awslabs.

the class CallableStatement method getObject.

@Override
public <T> T getObject(String parameterName, Class<T> type) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        // definitely not going to be from ?=
        ResultSetInternalMethods rs = getOutputParameters(0);
        T retValue = ((ResultSetImpl) rs).getObject(fixParameterName(parameterName), type);
        this.outputParamWasNull = rs.wasNull();
        return retValue;
    }
}
Also used : ResultSetInternalMethods(com.mysql.cj.jdbc.result.ResultSetInternalMethods) ResultSetImpl(com.mysql.cj.jdbc.result.ResultSetImpl)

Example 3 with ResultSetImpl

use of com.mysql.cj.jdbc.result.ResultSetImpl in project aws-mysql-jdbc by awslabs.

the class ResultSetRegressionTest method testBug96059.

/**
 * Tests fix for Bug#96059 (29999318), ERROR STREAMING MULTI RESULTSETS WITH MYSQL-CONNECTOR-JAVA 8.0.X.
 *
 * @throws Exception
 */
@Test
public void testBug96059() throws Exception {
    createTable("testBug96059", "(f1 int, f2 int, f3 int)");
    this.stmt.executeUpdate("INSERT INTO `testBug96059` VALUES (1,2,3),(4,5,6)");
    Connection con = null;
    Properties props = new Properties();
    props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
    props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
    props.setProperty(PropertyKey.allowMultiQueries.getKeyName(), "true");
    for (boolean useSSPS : new boolean[] { false, true }) {
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), "" + useSSPS);
        try {
            con = getConnectionWithProps(props);
            PreparedStatement st = con.prepareStatement("SELECT f1 from testBug96059;SELECT f2 from testBug96059;SELECT f3 from testBug96059;", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            st.setFetchSize(Integer.MIN_VALUE);
            st.setFetchDirection(ResultSet.FETCH_REVERSE);
            assertTrue(st.execute());
            // fetch results partially then try next result set
            this.rs = st.getResultSet();
            assertTrue(((ResultSetImpl) this.rs).getRows() instanceof ResultsetRowsStreaming<?>);
            assertTrue(this.rs.next());
            assertEquals(1, this.rs.getInt(1));
            assertTrue(st.getMoreResults());
            // fetch results fully then try next result set
            this.rs = st.getResultSet();
            assertTrue(((ResultSetImpl) this.rs).getRows() instanceof ResultsetRowsStreaming<?>);
            assertTrue(this.rs.next());
            assertEquals(2, this.rs.getInt(1));
            assertTrue(this.rs.next());
            assertEquals(5, this.rs.getInt(1));
            assertFalse(this.rs.next());
            assertTrue(st.getMoreResults());
            // fetch results partially then try next result set
            this.rs = st.getResultSet();
            assertTrue(((ResultSetImpl) this.rs).getRows() instanceof ResultsetRowsStreaming<?>);
            assertTrue(this.rs.next());
            assertEquals(3, this.rs.getInt(1));
            assertFalse(st.getMoreResults());
        } finally {
            if (con != null) {
                con.close();
            }
        }
    }
}
Also used : ResultSetImpl(com.mysql.cj.jdbc.result.ResultSetImpl) Connection(java.sql.Connection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 4 with ResultSetImpl

use of com.mysql.cj.jdbc.result.ResultSetImpl in project aws-mysql-jdbc by awslabs.

the class StatementImpl method getGeneratedKeysInternal.

protected ResultSetInternalMethods getGeneratedKeysInternal(long numKeys) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        String encoding = this.session.getServerSession().getCharsetSettings().getMetadataEncoding();
        int collationIndex = this.session.getServerSession().getCharsetSettings().getMetadataCollationIndex();
        Field[] fields = new Field[1];
        fields[0] = new Field("", "GENERATED_KEY", collationIndex, encoding, MysqlType.BIGINT_UNSIGNED, 20);
        ArrayList<Row> rowSet = new ArrayList<>();
        long beginAt = getLastInsertID();
        if (this.results != null) {
            String serverInfo = this.results.getServerInfo();
            // 
            if ((numKeys > 0) && (this.results.getFirstCharOfQuery() == 'R') && (serverInfo != null) && (serverInfo.length() > 0)) {
                numKeys = getRecordCountFromInfo(serverInfo);
            }
            if ((beginAt != 0) && (numKeys > 0)) {
                for (int i = 0; i < numKeys; i++) {
                    byte[][] row = new byte[1][];
                    if (beginAt > 0) {
                        row[0] = StringUtils.getBytes(Long.toString(beginAt));
                    } else {
                        byte[] asBytes = new byte[8];
                        asBytes[7] = (byte) (beginAt & 0xff);
                        asBytes[6] = (byte) (beginAt >>> 8);
                        asBytes[5] = (byte) (beginAt >>> 16);
                        asBytes[4] = (byte) (beginAt >>> 24);
                        asBytes[3] = (byte) (beginAt >>> 32);
                        asBytes[2] = (byte) (beginAt >>> 40);
                        asBytes[1] = (byte) (beginAt >>> 48);
                        asBytes[0] = (byte) (beginAt >>> 56);
                        BigInteger val = new BigInteger(1, asBytes);
                        row[0] = val.toString().getBytes();
                    }
                    rowSet.add(new ByteArrayRow(row, getExceptionInterceptor()));
                    beginAt += this.connection.getAutoIncrementIncrement();
                }
            }
        }
        ResultSetImpl gkRs = this.resultSetFactory.createFromResultsetRows(ResultSet.CONCUR_READ_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, new ResultsetRowsStatic(rowSet, new DefaultColumnDefinition(fields)));
        return gkRs;
    }
}
Also used : ResultSetImpl(com.mysql.cj.jdbc.result.ResultSetImpl) ArrayList(java.util.ArrayList) Field(com.mysql.cj.result.Field) DefaultColumnDefinition(com.mysql.cj.result.DefaultColumnDefinition) ResultsetRowsStatic(com.mysql.cj.protocol.a.result.ResultsetRowsStatic) BigInteger(java.math.BigInteger) Row(com.mysql.cj.result.Row) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow)

Aggregations

ResultSetImpl (com.mysql.cj.jdbc.result.ResultSetImpl)4 ResultSetInternalMethods (com.mysql.cj.jdbc.result.ResultSetInternalMethods)2 MysqlConnection (com.mysql.cj.MysqlConnection)1 JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)1 ServerPreparedStatement (com.mysql.cj.jdbc.ServerPreparedStatement)1 ByteArrayRow (com.mysql.cj.protocol.a.result.ByteArrayRow)1 ResultsetRowsStatic (com.mysql.cj.protocol.a.result.ResultsetRowsStatic)1 DefaultColumnDefinition (com.mysql.cj.result.DefaultColumnDefinition)1 Field (com.mysql.cj.result.Field)1 Row (com.mysql.cj.result.Row)1 BigInteger (java.math.BigInteger)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Test (org.junit.jupiter.api.Test)1