Search in sources :

Example 1 with ResultSetMetaData

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

the class ClientPreparedStatement method getMetaData.

@Override
public java.sql.ResultSetMetaData getMetaData() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (!isResultSetProducingQuery()) {
            return null;
        }
        JdbcPreparedStatement mdStmt = null;
        java.sql.ResultSet mdRs = null;
        if (this.pstmtResultMetaData == null) {
            try {
                mdStmt = new ClientPreparedStatement(this.connection, ((PreparedQuery<?>) this.query).getOriginalSql(), this.getCurrentDatabase(), getParseInfo());
                mdStmt.setMaxRows(1);
                int paramCount = ((PreparedQuery<?>) this.query).getParameterCount();
                for (int i = 1; i <= paramCount; i++) {
                    mdStmt.setString(i, null);
                }
                boolean hadResults = mdStmt.execute();
                if (hadResults) {
                    mdRs = mdStmt.getResultSet();
                    this.pstmtResultMetaData = mdRs.getMetaData();
                } else {
                    this.pstmtResultMetaData = new ResultSetMetaData(this.session, new Field[0], this.session.getPropertySet().getBooleanProperty(PropertyKey.useOldAliasMetadataBehavior).getValue(), this.session.getPropertySet().getBooleanProperty(PropertyKey.yearIsDateType).getValue(), this.exceptionInterceptor);
                }
            } finally {
                SQLException sqlExRethrow = null;
                if (mdRs != null) {
                    try {
                        mdRs.close();
                    } catch (SQLException sqlEx) {
                        sqlExRethrow = sqlEx;
                    }
                    mdRs = null;
                }
                if (mdStmt != null) {
                    try {
                        mdStmt.close();
                    } catch (SQLException sqlEx) {
                        sqlExRethrow = sqlEx;
                    }
                    mdStmt = null;
                }
                if (sqlExRethrow != null) {
                    throw sqlExRethrow;
                }
            }
        }
        return this.pstmtResultMetaData;
    }
}
Also used : CachedResultSetMetaData(com.mysql.cj.jdbc.result.CachedResultSetMetaData) ResultSetMetaData(com.mysql.cj.jdbc.result.ResultSetMetaData) Field(com.mysql.cj.result.Field) SQLException(java.sql.SQLException) ClientPreparedQuery(com.mysql.cj.ClientPreparedQuery) PreparedQuery(com.mysql.cj.PreparedQuery)

Aggregations

ClientPreparedQuery (com.mysql.cj.ClientPreparedQuery)1 PreparedQuery (com.mysql.cj.PreparedQuery)1 CachedResultSetMetaData (com.mysql.cj.jdbc.result.CachedResultSetMetaData)1 ResultSetMetaData (com.mysql.cj.jdbc.result.ResultSetMetaData)1 Field (com.mysql.cj.result.Field)1 SQLException (java.sql.SQLException)1