Search in sources :

Example 1 with QueryReturnType

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

the class ClientPreparedStatement method executeQuery.

@Override
public java.sql.ResultSet executeQuery() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        JdbcConnection locallyScopedConn = this.connection;
        if (!this.doPingInstead) {
            QueryReturnType queryReturnType = getParseInfo().getQueryReturnType();
            if (queryReturnType != QueryReturnType.PRODUCES_RESULT_SET && queryReturnType != QueryReturnType.MAY_PRODUCE_RESULT_SET) {
                throw SQLError.createSQLException(Messages.getString("Statement.57"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
            }
        }
        this.batchedGeneratedKeys = null;
        resetCancelledState();
        implicitlyCloseAllOpenResults();
        clearWarnings();
        if (this.doPingInstead) {
            doPingInstead();
            return this.results;
        }
        setupStreamingTimeout(locallyScopedConn);
        Message sendPacket = ((PreparedQuery<?>) this.query).fillSendPacket();
        String oldDb = null;
        if (!locallyScopedConn.getDatabase().equals(this.getCurrentDatabase())) {
            oldDb = locallyScopedConn.getDatabase();
            locallyScopedConn.setDatabase(this.getCurrentDatabase());
        }
        // 
        // Check if we have cached metadata for this query...
        // 
        CachedResultSetMetaData cachedMetadata = null;
        boolean cacheResultSetMetadata = locallyScopedConn.getPropertySet().getBooleanProperty(PropertyKey.cacheResultSetMetadata).getValue();
        String origSql = ((PreparedQuery<?>) this.query).getOriginalSql();
        if (cacheResultSetMetadata) {
            cachedMetadata = locallyScopedConn.getCachedMetaData(origSql);
        }
        locallyScopedConn.setSessionMaxRows(this.maxRows);
        this.results = executeInternal(this.maxRows, sendPacket, createStreamingResultSet(), true, cachedMetadata, false);
        if (oldDb != null) {
            locallyScopedConn.setDatabase(oldDb);
        }
        if (cachedMetadata != null) {
            locallyScopedConn.initializeResultsMetadataFromCache(origSql, cachedMetadata, this.results);
        } else {
            if (cacheResultSetMetadata) {
                locallyScopedConn.initializeResultsMetadataFromCache(origSql, null, /* will be created */
                this.results);
            }
        }
        this.lastInsertId = this.results.getUpdateID();
        return this.results;
    }
}
Also used : Message(com.mysql.cj.protocol.Message) CachedResultSetMetaData(com.mysql.cj.jdbc.result.CachedResultSetMetaData) QueryReturnType(com.mysql.cj.QueryReturnType) ClientPreparedQuery(com.mysql.cj.ClientPreparedQuery) PreparedQuery(com.mysql.cj.PreparedQuery)

Aggregations

ClientPreparedQuery (com.mysql.cj.ClientPreparedQuery)1 PreparedQuery (com.mysql.cj.PreparedQuery)1 QueryReturnType (com.mysql.cj.QueryReturnType)1 CachedResultSetMetaData (com.mysql.cj.jdbc.result.CachedResultSetMetaData)1 Message (com.mysql.cj.protocol.Message)1