Search in sources :

Example 1 with ResultsetRow

use of com.mysql.cj.protocol.ResultsetRow in project ABC by RuiPinto96274.

the class TextResultsetReader method read.

@Override
public Resultset read(int maxRows, boolean streamResults, NativePacketPayload resultPacket, ColumnDefinition metadata, ProtocolEntityFactory<Resultset, NativePacketPayload> resultSetFactory) throws IOException {
    Resultset rs = null;
    // try {
    long columnCount = resultPacket.readInteger(IntegerDataType.INT_LENENC);
    if (columnCount > 0) {
        // Build a result set with rows.
        // Read in the column information
        ColumnDefinition cdef = this.protocol.read(ColumnDefinition.class, new ColumnDefinitionFactory(columnCount, metadata));
        // There is no EOF packet after fields when CLIENT_DEPRECATE_EOF is set
        if (!this.protocol.getServerSession().isEOFDeprecated()) {
            this.protocol.skipPacket();
        // this.protocol.readServerStatusForResultSets(this.protocol.readPacket(this.protocol.getReusablePacket()), true);
        }
        ResultsetRows rows = null;
        if (!streamResults) {
            TextRowFactory trf = new TextRowFactory(this.protocol, cdef, resultSetFactory.getResultSetConcurrency(), false);
            ArrayList<ResultsetRow> rowList = new ArrayList<>();
            ResultsetRow row = this.protocol.read(ResultsetRow.class, trf);
            while (row != null) {
                if ((maxRows == -1) || (rowList.size() < maxRows)) {
                    rowList.add(row);
                }
                row = this.protocol.read(ResultsetRow.class, trf);
            }
            rows = new ResultsetRowsStatic(rowList, cdef);
        } else {
            rows = new ResultsetRowsStreaming<>(this.protocol, cdef, false, resultSetFactory);
            this.protocol.setStreamingData(rows);
        }
        /*
             * Build ResultSet from ResultsetRows
             */
        rs = resultSetFactory.createFromProtocolEntity(rows);
    } else {
        // check for file request
        if (columnCount == NativePacketPayload.NULL_LENGTH) {
            String charEncoding = this.protocol.getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue();
            String fileName = resultPacket.readString(StringSelfDataType.STRING_TERM, this.protocol.getServerSession().getCharsetSettings().doesPlatformDbCharsetMatches() ? charEncoding : null);
            resultPacket = this.protocol.sendFileToServer(fileName);
        }
        /*
             * Build ResultSet with no ResultsetRows
             */
        // read and parse OK packet
        // oldStatus set in sendCommand()
        OkPacket ok = this.protocol.readServerStatusForResultSets(resultPacket, false);
        rs = resultSetFactory.createFromProtocolEntity(ok);
    }
    return rs;
// } catch (IOException ioEx) {
// throw SQLError.createCommunicationsException(this.protocol.getConnection(), this.protocol.getPacketSentTimeHolder().getLastPacketSentTime(),
// this.protocol.getPacketReceivedTimeHolder().getLastPacketReceivedTime(), ioEx, this.protocol.getExceptionInterceptor());
// }
}
Also used : OkPacket(com.mysql.cj.protocol.a.result.OkPacket) ArrayList(java.util.ArrayList) ResultsetRows(com.mysql.cj.protocol.ResultsetRows) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) ResultsetRow(com.mysql.cj.protocol.ResultsetRow) ResultsetRowsStatic(com.mysql.cj.protocol.a.result.ResultsetRowsStatic) Resultset(com.mysql.cj.protocol.Resultset)

Example 2 with ResultsetRow

use of com.mysql.cj.protocol.ResultsetRow in project ABC by RuiPinto96274.

the class UpdatableResultSet method insertRow.

@Override
public void insertRow() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (!this.onInsertRow) {
            throw SQLError.createSQLException(Messages.getString("UpdatableResultSet.7"), getExceptionInterceptor());
        }
        this.inserter.executeUpdate();
        long autoIncrementId = this.inserter.getLastInsertID();
        Field[] fields = this.getMetadata().getFields();
        byte[][] newRow = new byte[fields.length][];
        for (int i = 0; i < fields.length; i++) {
            newRow[i] = this.inserter.isNull(i + 1) ? null : this.inserter.getBytesRepresentation(i + 1);
            // WARN: This non-variant only holds if MySQL never allows more than one auto-increment key (which is the way it is _today_)
            if (fields[i].isAutoIncrement() && autoIncrementId > 0) {
                newRow[i] = StringUtils.getBytes(String.valueOf(autoIncrementId));
                this.inserter.setBytesNoEscapeNoQuotes(i + 1, newRow[i]);
            }
        }
        Row resultSetRow = new ByteArrayRow(newRow, getExceptionInterceptor());
        // inserter is always a client-side prepared statement, so it's safe to use it with ByteArrayRow for server-side prepared statement too
        refreshRow(this.inserter, resultSetRow);
        this.rowData.addRow(resultSetRow);
        resetInserter();
    }
}
Also used : Field(com.mysql.cj.result.Field) ResultsetRow(com.mysql.cj.protocol.ResultsetRow) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow) Row(com.mysql.cj.result.Row) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow)

Example 3 with ResultsetRow

use of com.mysql.cj.protocol.ResultsetRow in project JavaSegundasQuintas by ecteruel.

the class UpdatableResultSet method insertRow.

@Override
public void insertRow() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (!this.onInsertRow) {
            throw SQLError.createSQLException(Messages.getString("UpdatableResultSet.7"), getExceptionInterceptor());
        }
        this.inserter.executeUpdate();
        long autoIncrementId = this.inserter.getLastInsertID();
        Field[] fields = this.getMetadata().getFields();
        byte[][] newRow = new byte[fields.length][];
        for (int i = 0; i < fields.length; i++) {
            newRow[i] = this.inserter.isNull(i + 1) ? null : this.inserter.getBytesRepresentation(i + 1);
            // WARN: This non-variant only holds if MySQL never allows more than one auto-increment key (which is the way it is _today_)
            if (fields[i].isAutoIncrement() && autoIncrementId > 0) {
                newRow[i] = StringUtils.getBytes(String.valueOf(autoIncrementId));
                this.inserter.setBytesNoEscapeNoQuotes(i + 1, newRow[i]);
            }
        }
        Row resultSetRow = new ByteArrayRow(newRow, getExceptionInterceptor());
        // inserter is always a client-side prepared statement, so it's safe to use it with ByteArrayRow for server-side prepared statement too
        refreshRow(this.inserter, resultSetRow);
        this.rowData.addRow(resultSetRow);
        resetInserter();
    }
}
Also used : Field(com.mysql.cj.result.Field) ResultsetRow(com.mysql.cj.protocol.ResultsetRow) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow) Row(com.mysql.cj.result.Row) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow)

Example 4 with ResultsetRow

use of com.mysql.cj.protocol.ResultsetRow in project JavaSegundasQuintas by ecteruel.

the class BinaryResultsetReader method read.

@Override
public Resultset read(int maxRows, boolean streamResults, NativePacketPayload resultPacket, ColumnDefinition metadata, ProtocolEntityFactory<Resultset, NativePacketPayload> resultSetFactory) throws IOException {
    Resultset rs = null;
    // try {
    long columnCount = resultPacket.readInteger(IntegerDataType.INT_LENENC);
    if (columnCount > 0) {
        // Build a result set with rows.
        // Read in the column information
        ColumnDefinition cdef = this.protocol.read(ColumnDefinition.class, new MergingColumnDefinitionFactory(columnCount, metadata));
        boolean isCursorPossible = this.protocol.getPropertySet().getBooleanProperty(PropertyKey.useCursorFetch).getValue() && resultSetFactory.getResultSetType() == Type.FORWARD_ONLY && resultSetFactory.getFetchSize() > 0;
        // If CLIENT_DEPRECATE_EOF is set, there is no way to tell which one, OK or ResultsetRow, is the next packet, so it should be read with a special caching method.
        if (isCursorPossible || !this.protocol.getServerSession().isEOFDeprecated()) {
            // Read the next packet but leave it in the reader cache. In case it's not the OK or EOF one it will be read again by ResultSet factories.
            NativePacketPayload rowPacket = this.protocol.probeMessage(this.protocol.getReusablePacket());
            this.protocol.checkErrorMessage(rowPacket);
            if (rowPacket.isResultSetOKPacket() || rowPacket.isEOFPacket()) {
                // Consume the OK/EOF packet from the reader cache and read the status flags from it;
                // The SERVER_STATUS_CURSOR_EXISTS flag should indicate the cursor state in this case.
                rowPacket = this.protocol.readMessage(this.protocol.getReusablePacket());
                this.protocol.readServerStatusForResultSets(rowPacket, true);
            } else {
                // If it's not an OK/EOF then the cursor is not created and this recent packet is a row.
                // Retain the packet in the reader cache.
                isCursorPossible = false;
            }
        }
        ResultsetRows rows = null;
        if (isCursorPossible && this.protocol.getServerSession().cursorExists()) {
            rows = new ResultsetRowsCursor(this.protocol, cdef);
        } else if (!streamResults) {
            BinaryRowFactory brf = new BinaryRowFactory(this.protocol, cdef, resultSetFactory.getResultSetConcurrency(), false);
            ArrayList<ResultsetRow> rowList = new ArrayList<>();
            ResultsetRow row = this.protocol.read(ResultsetRow.class, brf);
            while (row != null) {
                if ((maxRows == -1) || (rowList.size() < maxRows)) {
                    rowList.add(row);
                }
                row = this.protocol.read(ResultsetRow.class, brf);
            }
            rows = new ResultsetRowsStatic(rowList, cdef);
        } else {
            rows = new ResultsetRowsStreaming<>(this.protocol, cdef, true, resultSetFactory);
            this.protocol.setStreamingData(rows);
        }
        /*
             * Build ResultSet from ResultsetRows
             */
        rs = resultSetFactory.createFromProtocolEntity(rows);
    } else {
        // check for file request
        if (columnCount == NativePacketPayload.NULL_LENGTH) {
            String charEncoding = this.protocol.getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue();
            String fileName = resultPacket.readString(StringSelfDataType.STRING_TERM, this.protocol.getServerSession().getCharsetSettings().doesPlatformDbCharsetMatches() ? null : charEncoding);
            resultPacket = this.protocol.sendFileToServer(fileName);
        }
        /*
             * Build ResultSet with no ResultsetRows
             */
        // read and parse OK packet
        // oldStatus set in sendCommand()
        OkPacket ok = this.protocol.readServerStatusForResultSets(resultPacket, false);
        rs = resultSetFactory.createFromProtocolEntity(ok);
    }
    return rs;
}
Also used : OkPacket(com.mysql.cj.protocol.a.result.OkPacket) ArrayList(java.util.ArrayList) ResultsetRows(com.mysql.cj.protocol.ResultsetRows) ResultsetRowsStreaming(com.mysql.cj.protocol.a.result.ResultsetRowsStreaming) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) ResultsetRow(com.mysql.cj.protocol.ResultsetRow) ResultsetRowsCursor(com.mysql.cj.protocol.a.result.ResultsetRowsCursor) ResultsetRowsStatic(com.mysql.cj.protocol.a.result.ResultsetRowsStatic) Resultset(com.mysql.cj.protocol.Resultset)

Example 5 with ResultsetRow

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

the class UpdatableResultSet method insertRow.

@Override
public void insertRow() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (!this.onInsertRow) {
            throw SQLError.createSQLException(Messages.getString("UpdatableResultSet.7"), getExceptionInterceptor());
        }
        this.inserter.executeUpdate();
        long autoIncrementId = this.inserter.getLastInsertID();
        Field[] fields = this.getMetadata().getFields();
        byte[][] newRow = new byte[fields.length][];
        for (int i = 0; i < fields.length; i++) {
            newRow[i] = this.inserter.isNull(i + 1) ? null : this.inserter.getBytesRepresentation(i + 1);
            // WARN: This non-variant only holds if MySQL never allows more than one auto-increment key (which is the way it is _today_)
            if (fields[i].isAutoIncrement() && autoIncrementId > 0) {
                newRow[i] = StringUtils.getBytes(String.valueOf(autoIncrementId));
                this.inserter.setBytesNoEscapeNoQuotes(i + 1, newRow[i]);
            }
        }
        Row resultSetRow = new ByteArrayRow(newRow, getExceptionInterceptor());
        // inserter is always a client-side prepared statement, so it's safe to use it with ByteArrayRow for server-side prepared statement too
        refreshRow(this.inserter, resultSetRow);
        this.rowData.addRow(resultSetRow);
        resetInserter();
    }
}
Also used : Field(com.mysql.cj.result.Field) ResultsetRow(com.mysql.cj.protocol.ResultsetRow) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow) Row(com.mysql.cj.result.Row) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow)

Aggregations

ResultsetRow (com.mysql.cj.protocol.ResultsetRow)9 ColumnDefinition (com.mysql.cj.protocol.ColumnDefinition)6 Resultset (com.mysql.cj.protocol.Resultset)6 ResultsetRows (com.mysql.cj.protocol.ResultsetRows)6 OkPacket (com.mysql.cj.protocol.a.result.OkPacket)6 ResultsetRowsStatic (com.mysql.cj.protocol.a.result.ResultsetRowsStatic)6 ArrayList (java.util.ArrayList)6 ByteArrayRow (com.mysql.cj.protocol.a.result.ByteArrayRow)3 ResultsetRowsCursor (com.mysql.cj.protocol.a.result.ResultsetRowsCursor)3 ResultsetRowsStreaming (com.mysql.cj.protocol.a.result.ResultsetRowsStreaming)3 Field (com.mysql.cj.result.Field)3 Row (com.mysql.cj.result.Row)3