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;
}
}
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;
}
}
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();
}
}
}
}
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;
}
}
Aggregations