private static int encodeTableColumnAttrs(ColumnBase column) {

    int out = column.getNullability(); // always between 0x00 and 0x02

    if (column.isIdentity()) {
      out |= 0x00000010;
    }

    return out;
  }
Ejemplo n.º 2
0
  private Result newColumnResult(long position, int count) throws SQLException {

    int mArraySize = 0;
    String mArrayStruct = data.getTypeStructure();
    ArrayList<Integer> dimSize = getDimSize(mArrayStruct);
    ArrayList<Integer> iterIndex = new ArrayList<>(); // go through all the array values

    for (int i = 0; i < dimSize.size(); i++) {
      mArraySize += dimSize.get(i);
    }

    // tests if the required elements exist. The limits are determined
    // by computing the product of each dimension's size
    if (!JDBCClobClient.isInLimits(mArraySize, position, count)) {
      throw JDBCUtil.outOfRangeArgument();
    }

    Type[] types = new Type[2];

    types[0] = Type.SQL_VARCHAR;
    types[1] = elementType;

    ResultMetaData meta = ResultMetaData.newSimpleResultMetaData(types);

    meta.columnLabels = new String[] {"C1", "C2"};
    meta.colIndexes = new int[] {-1, -1};
    meta.columns = new ColumnBase[2];

    ColumnBase column = new ColumnBase("", "", "", "");

    column.setType(types[0]);

    meta.columns[0] = column;
    column = new ColumnBase("", "", "", "");

    column.setType(types[1]);

    meta.columns[1] = column;

    RowSetNavigatorClient navigator = new RowSetNavigatorClient();

    for (int i = (int) position; i < position + count; i++) {
      Object[] rowData = new Object[2];

      rowData[0] = Integer.valueOf(i + 1);
      try {
        rowData[1] = data.getCell(new RasPoint(1, 1));
      } catch (RasDimensionMismatchException | RasIndexOutOfBoundsException e) {
        System.err.println("Can't get the cell at point (1, 1)");
        e.printStackTrace();
      }

      navigator.add(rowData);
    }

    Result result = Result.newDataResult(meta);

    result.setNavigator(navigator);

    return result;
  }
  void write(RowOutputInterface out) throws IOException {

    out.writeInt(type);
    out.writeInt(columnCount);

    switch (type) {
      case UPDATE_RESULT_METADATA:
      case SIMPLE_RESULT_METADATA:
        {
          for (int i = 0; i < columnCount; i++) {
            out.writeType(columnTypes[i].typeCode);
          }

          return;
        }
      case GENERATED_INDEX_METADATA:
        {
          for (int i = 0; i < columnCount; i++) {
            out.writeInt(colIndexes[i]);
          }

          return;
        }
      case GENERATED_NAME_METADATA:
        {
          for (int i = 0; i < columnCount; i++) {
            out.writeString(columnLabels[i]);
          }

          return;
        }
      case PARAM_METADATA:
        for (int i = 0; i < columnCount; i++) {
          writeDataType(out, columnTypes[i]);
          out.writeString(columnLabels[i]);
          out.writeByte(encodeParamColumnAttrs(i));
        }

        return;

      case RESULT_METADATA:
        {
          out.writeInt(extendedColumnCount);

          for (int i = 0; i < extendedColumnCount; i++) {
            if (columnTypes[i] == null) {
              ColumnBase column = columns[i];

              columnTypes[i] = column.getDataType();
            }

            writeDataType(out, columnTypes[i]);
          }

          for (int i = 0; i < columnCount; i++) {
            ColumnBase column = columns[i];

            out.writeString(columnLabels[i]);
            out.writeString(column.getCatalogNameString());
            out.writeString(column.getSchemaNameString());
            out.writeString(column.getTableNameString());
            out.writeString(column.getNameString());
            out.writeByte(encodeTableColumnAttrs(column));
          }

          if (columnCount != extendedColumnCount) {
            for (int i = 0; i < colIndexes.length; i++) {
              out.writeInt(colIndexes[i]);
            }
          }

          return;
        }
      default:
        {
          throw Error.runtimeError(ErrorCode.U_S0500, "ResultMetaData");
        }
    }
  }
  ResultMetaData(RowInputBinary in) throws IOException {

    type = in.readInt();
    columnCount = in.readInt();

    switch (type) {
      case UPDATE_RESULT_METADATA:
      case SIMPLE_RESULT_METADATA:
        {
          columnTypes = new Type[columnCount];

          for (int i = 0; i < columnCount; i++) {
            int type = in.readType();

            columnTypes[i] = Type.getDefaultType(type);
          }

          return;
        }
      case GENERATED_INDEX_METADATA:
        {
          colIndexes = new int[columnCount];

          for (int i = 0; i < columnCount; i++) {
            colIndexes[i] = in.readInt();
          }

          return;
        }
      case GENERATED_NAME_METADATA:
        {
          columnLabels = new String[columnCount];

          for (int i = 0; i < columnCount; i++) {
            columnLabels[i] = in.readString();
          }

          return;
        }
      case PARAM_METADATA:
        {
          columnTypes = new Type[columnCount];
          columnLabels = new String[columnCount];
          paramModes = new byte[columnCount];
          paramNullable = new byte[columnCount];

          for (int i = 0; i < columnCount; i++) {
            columnTypes[i] = readDataType(in);
            columnLabels[i] = in.readString();

            decodeParamColumnAttrs(in.readByte(), i);
          }

          return;
        }
      case RESULT_METADATA:
        {
          extendedColumnCount = in.readInt();
          columnTypes = new Type[extendedColumnCount];
          columnLabels = new String[columnCount];
          columns = new ColumnBase[columnCount];

          if (columnCount != extendedColumnCount) {
            colIndexes = new int[columnCount];
          }

          for (int i = 0; i < extendedColumnCount; i++) {
            Type type = readDataType(in);

            columnTypes[i] = type;
          }

          for (int i = 0; i < columnCount; i++) {
            columnLabels[i] = in.readString();

            String catalog = in.readString();
            String schema = in.readString();
            String table = in.readString();
            String name = in.readString();
            ColumnBase column = new ColumnBase(catalog, schema, table, name);

            column.setType(columnTypes[i]);
            decodeTableColumnAttrs(in.readByte(), column);

            columns[i] = column;
          }

          if (columnCount != extendedColumnCount) {
            for (int i = 0; i < columnCount; i++) {
              colIndexes[i] = in.readInt();
            }
          }

          return;
        }
      default:
        {
          throw Error.runtimeError(ErrorCode.U_S0500, "ResultMetaData");
        }
    }
  }
 private static void decodeTableColumnAttrs(int in, ColumnBase column) {
   column.setNullability((byte) (in & 0x0000000f));
   column.setIdentity((in & 0x00000010) != 0);
 }