use of io.shardingjdbc.proxy.transport.mysql.packet.command.text.query.FieldCountPacket in project sharding-jdbc by shardingjdbc.
the class SQLExecuteBackendHandler method buildPackets.
private List<DatabaseProtocolPacket> buildPackets(final List<List<DatabaseProtocolPacket>> packets, final MergedResult mergedResult) {
List<DatabaseProtocolPacket> result = new LinkedList<>();
Iterator<DatabaseProtocolPacket> databaseProtocolPacketsSampling = packets.iterator().next().iterator();
FieldCountPacket fieldCountPacketSampling = (FieldCountPacket) databaseProtocolPacketsSampling.next();
result.add(fieldCountPacketSampling);
int columnCount = fieldCountPacketSampling.getColumnCount();
for (int i = 0; i < columnCount; i++) {
result.add(databaseProtocolPacketsSampling.next());
}
result.add(databaseProtocolPacketsSampling.next());
int currentSequenceId = result.size();
try {
while (mergedResult.next()) {
List<Object> data = new ArrayList<>(columnCount);
for (int i = 1; i <= columnCount; i++) {
data.add(mergedResult.getValue(i, Object.class));
}
result.add(new TextResultSetRowPacket(++currentSequenceId, data));
}
} catch (final SQLException ex) {
return Collections.<DatabaseProtocolPacket>singletonList(new ErrPacket(1, ex.getErrorCode(), "", ex.getSQLState(), ex.getMessage()));
}
result.add(new EofPacket(++currentSequenceId, 0, StatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue()));
return result;
}
use of io.shardingjdbc.proxy.transport.mysql.packet.command.text.query.FieldCountPacket in project sharding-jdbc by shardingjdbc.
the class SQLExecuteBackendHandler method getDatabaseProtocolPackets.
private List<DatabaseProtocolPacket> getDatabaseProtocolPackets(final ResultSet resultSet) throws SQLException {
List<DatabaseProtocolPacket> result = new LinkedList<>();
int currentSequenceId = 0;
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int columnCount = resultSetMetaData.getColumnCount();
if (0 == columnCount) {
result.add(new OKPacket(++currentSequenceId, 0, 0, StatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue(), 0, ""));
return result;
}
result.add(new FieldCountPacket(++currentSequenceId, columnCount));
for (int i = 1; i <= columnCount; i++) {
result.add(new ColumnDefinition41Packet(++currentSequenceId, resultSetMetaData.getSchemaName(i), resultSetMetaData.getTableName(i), resultSetMetaData.getTableName(i), resultSetMetaData.getColumnLabel(i), resultSetMetaData.getColumnName(i), resultSetMetaData.getColumnDisplaySize(i), ColumnType.valueOfJDBCType(resultSetMetaData.getColumnType(i)), 0));
}
result.add(new EofPacket(++currentSequenceId, 0, StatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue()));
while (resultSet.next()) {
List<Object> data = new ArrayList<>(columnCount);
for (int i = 1; i <= columnCount; i++) {
data.add(resultSet.getObject(i));
}
result.add(new TextResultSetRowPacket(++currentSequenceId, data));
}
result.add(new EofPacket(++currentSequenceId, 0, StatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue()));
return result;
}
Aggregations