Get BigDecimal from raw binary format.

@param columnInfo column information
@return BigDecimal value
@throws SQLException if column is not numeric
485143
public BigDecimal getInternalBigDecimal(ColumnInformation columnInfo) throws SQLException {
    if (lastValueWasNull()) {
      return null;
    }

    switch (columnInfo.getColumnType()) {
      case BIT:
        return BigDecimal.valueOf(parseBit());
      case TINYINT:
        return BigDecimal.valueOf((long) getInternalTinyInt(columnInfo));
      case SMALLINT:
      case YEAR:
        return BigDecimal.valueOf((long) getInternalSmallInt(columnInfo));
      case INTEGER:
      case MEDIUMINT:
        return BigDecimal.valueOf(getInternalMediumInt(columnInfo));
      case BIGINT:
        long value = ((buf[pos] & 0xff)
            + ((long) (buf[pos + 1] & 0xff) << 8)
            + ((long) (buf[pos + 2] & 0xff) << 16)
            + ((long) (buf[pos + 3] & 0xff) << 24)
            + ((long) (buf[pos + 4] & 0xff) << 32)
            + ((long) (buf[pos + 5] & 0xff) << 40)
            + ((long) (buf[pos + 6] & 0xff) << 48)
            + ((long) (buf[pos + 7] & 0xff) << 56)
        );
        if (columnInfo.isSigned()) {
          return new BigDecimal(String.valueOf(BigInteger.valueOf(value)))
              .setScale(columnInfo.getDecimals());
        } else {
          return new BigDecimal(String.valueOf(new BigInteger(1, new byte[]{(byte) (value >> 56),
              (byte) (value >> 48), (byte) (value >> 40), (byte) (value >> 32),
              (byte) (value >> 24), (byte) (value >> 16), (byte) (value >> 8),
              (byte) value}))).setScale(columnInfo.getDecimals());
        }
      case FLOAT:
        return BigDecimal.valueOf(getInternalFloat(columnInfo));
      case DOUBLE:
        return BigDecimal.valueOf(getInternalDouble(columnInfo));
      case DECIMAL:
      case VARSTRING:
      case VARCHAR:
      case STRING:
      case OLDDECIMAL:
        return new BigDecimal(new String(buf, pos, length, StandardCharsets.UTF_8));
      default:
        throw new SQLException("getBigDecimal not available for data field type "
            + columnInfo.getColumnType().getJavaTypeName());
    }
  }
534138
@Override
    public byte[] getBytes(int columnIndex) throws SQLException {
        checkColumnBounds(columnIndex);
        try {
            if (table.getColumnType(columnIndex - 1) == VoltType.STRING)
                return table.getStringAsBytes(columnIndex - 1);
            else if (table.getColumnType(columnIndex - 1) == VoltType.VARBINARY)
                return table.getVarbinary(columnIndex - 1);
            else
                throw SQLError.get(SQLError.CONVERSION_NOT_FOUND,
                        table.getColumnType(columnIndex - 1), "byte[]");
        } catch (SQLException x) {
            throw x;
        } catch (Exception x) {
            throw SQLError.get(x);
        }
    }
650622
public BigInteger getInternalBigInteger(ColumnInformation columnInfo) {
    if (lastValueWasNull()) {
      return null;
    }
    return new BigInteger(new String(buf, pos, length, StandardCharsets.UTF_8));
  }
1048596
public BigDecimal toBigDecimal() {

        StringBuilder sb = new StringBuilder();
        this.createNumber(sb);
        return new BigDecimal(sb.toString());

    }
459626
@Override
	public void updateBigDecimal(final int columnIndex, final BigDecimal x) throws SQLException {
		wrapped.updateBigDecimal(columnIndex, x);
	}
231691
@Override
	public Object toJdbc(final BigInteger original, final Connection connection,
			final BindParameterMapperManager parameterMapperManager) {
		return new BigDecimal(original);
	}
15002
private static BigDecimal doCalculate(String formula) throws Exception {
        Stack<BigDecimal> stack = new Stack<>();
        BigDecimal result = BigDecimal.valueOf(0);
        BigDecimal number = BigDecimal.valueOf(0);
        char sign = '+';
        boolean isDecimal = false;
        BigDecimal decimalSign = new BigDecimal(0.1);

        for (int i = 0; i < formula.length(); i++) {
            char c = formula.charAt(i);
            if (Character.isDigit(c)) {
                BigDecimal num = new BigDecimal(c - '0');
                number = isDecimal ? number.add(num.multiply(decimalSign)) : num.add(number.multiply(BigDecimal
                        .valueOf(10)));
                decimalSign = decimalSign.multiply(BigDecimal.valueOf(0.1));
            } else if (c == '.') {
                isDecimal = true;
                decimalSign = BigDecimal.valueOf(0.1);
            } else if (c == '(') {
                BigDecimal[] res = calculateInlineFormula(i + 1, formula);
                number = number.compareTo(BigDecimal.valueOf(0)) == 0 ? res[0] : number.multiply(res[0]);
                i = res[1].intValue();
            }
            boolean isNotDigit = (!Character.isDigit(c) && c != '.' && c != '(') || i == formula.length() - 1;
            if (isNotDigit) {
                if (sign == '+') {
                    stack.push(number);
                } else if (sign == '-') {
                    stack.push(number.multiply(BigDecimal.valueOf(-1)));
                } else if (sign == '*') {
                    stack.push(number.multiply(stack.pop()));
                } else if (sign == '/') {
                    stack.push(stack.pop().divide(number, getPrecision(), BigDecimal.ROUND_HALF_UP));
                }
                sign = c;
                isDecimal = false;
                number = BigDecimal.valueOf(0);
            }
        }
        for (BigDecimal i : stack) {
            result = result.add(i);
        }
        return result.setScale(getPrecision(), BigDecimal.ROUND_HALF_UP);
    }
1142740
public BigDecimal getBigDecimal( int index ) throws OdaException
	{
		BigDecimal value = (BigDecimal) getFieldValue(index);
		return  value==null?new BigDecimal(0):value;
	}
395022
public long getInternalLong(ColumnInformation columnInfo) throws SQLException {
    if (lastValueWasNull()) {
      return 0;
    }
    try {
      switch (columnInfo.getColumnType()) {
        case FLOAT:
          Float floatValue = Float.valueOf(new String(buf, pos, length, StandardCharsets.UTF_8));
          if (floatValue.compareTo((float) Long.MAX_VALUE) >= 1) {
            throw new SQLException(
                "Out of range value for column '" + columnInfo.getName() + "' : value "
                    + new String(buf, pos, length, StandardCharsets.UTF_8)
                    + " is not in Long range", "22003", 1264);
          }
          return floatValue.longValue();
        case DOUBLE:
          Double doubleValue = Double.valueOf(new String(buf, pos, length, StandardCharsets.UTF_8));
          if (doubleValue.compareTo((double) Long.MAX_VALUE) >= 1) {
            throw new SQLException(
                "Out of range value for column '" + columnInfo.getName() + "' : value "
                    + new String(buf, pos, length, StandardCharsets.UTF_8)
                    + " is not in Long range", "22003", 1264);
          }
          return doubleValue.longValue();
        case BIT:
          return parseBit();
        case TINYINT:
        case SMALLINT:
        case YEAR:
        case INTEGER:
        case MEDIUMINT:
        case BIGINT:
          long result = 0;
          boolean negate = false;
          int begin = pos;
          if (length > 0 && buf[begin] == 45) { //minus sign
            negate = true;
            begin++;
          }
          for (; begin < pos + length; begin++) {
            result = result * 10 + buf[begin] - 48;
          }
          //specific for BIGINT : if value > Long.MAX_VALUE , will become negative until -1
          if (result < 0) {
            //CONJ-399 : handle specifically Long.MIN_VALUE that has absolute value +1 compare to LONG.MAX_VALUE
            if (result == Long.MIN_VALUE && negate) {
              return Long.MIN_VALUE;
            }
            throw new SQLException(
                "Out of range value for column '" + columnInfo.getName() + "' for value "
                    + new String(buf, pos, length, StandardCharsets.UTF_8), "22003", 1264);
          }
          return (negate ? -1 * result : result);
        default:
          return Long.parseLong(new String(buf, pos, length, StandardCharsets.UTF_8));
      }

    } catch (NumberFormatException nfe) {
      //parse error.
      //if its a decimal retry without the decimal part.
      String value = new String(buf, pos, length, StandardCharsets.UTF_8);
      if (isIntegerRegex.matcher(value).find()) {
        try {
          return Long.parseLong(value.substring(0, value.indexOf(".")));
        } catch (NumberFormatException nfee) {
          //eat exception
        }
      }
      throw new SQLException(
          "Out of range value for column '" + columnInfo.getName() + "' : value " + value, "22003",
          1264);
    }
  }
89740
@Override
    public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException
    {
        checkClosed();
        throw SQLError.noSupport();
    }
571444
public static BigDecimal toBigDecimal(Number number) {
		if (null == number) {
			return BigDecimal.ZERO;
		}
		return toBigDecimal(number.toString());
	}
239152
public synchronized BigDecimal getBigDecimal(int parameterIndex,
            int scale) throws SQLException {

        if (scale < 0) {
            throw Util.outOfRangeArgument();
        }

        // boucherb@users 20020502 - added conversion
        BigDecimal bd = (BigDecimal) getColumnInType(parameterIndex,
            Type.SQL_DECIMAL);

        if (bd != null) {
            bd = bd.setScale(scale, BigDecimal.ROUND_DOWN);
        }

        return bd;
    }
621931
@Override
	@Deprecated
	public BigDecimal getBigDecimal(final int columnIndex, final int scale) throws SQLException {
		return wrapped.getBigDecimal(columnIndex, scale);
	}
953858
public String getInternalTimeString(ColumnInformation columnInfo) {
    if (lastValueWasNull()) {
      return null;
    }
    if (length == 0) {
      // binary send 00:00:00 as 0.
      if (columnInfo.getDecimals() == 0) {
        return "00:00:00";
      } else {
        StringBuilder value = new StringBuilder("00:00:00.");
        int decimal = columnInfo.getDecimals();
        while (decimal-- > 0) {
          value.append("0");
        }
        return value.toString();
      }
    }
    String rawValue = new String(buf, pos, length, StandardCharsets.UTF_8);
    if ("0000-00-00".equals(rawValue)) {
      return null;
    }

    int day = ((buf[pos + 1] & 0xff)
        | ((buf[pos + 2] & 0xff) << 8)
        | ((buf[pos + 3] & 0xff) << 16)
        | ((buf[pos + 4] & 0xff) << 24));
    int hour = buf[pos + 5];
    int timeHour = hour + day * 24;

    String hourString;
    if (timeHour < 10) {
      hourString = "0" + timeHour;
    } else {
      hourString = Integer.toString(timeHour);
    }

    String minuteString;
    int minutes = buf[pos + 6];
    if (minutes < 10) {
      minuteString = "0" + minutes;
    } else {
      minuteString = Integer.toString(minutes);
    }

    String secondString;
    int seconds = buf[pos + 7];
    if (seconds < 10) {
      secondString = "0" + seconds;
    } else {
      secondString = Integer.toString(seconds);
    }

    int microseconds = 0;
    if (length > 8) {
      microseconds = ((buf[pos + 8] & 0xff)
          | (buf[pos + 9] & 0xff) << 8
          | (buf[pos + 10] & 0xff) << 16
          | (buf[pos + 11] & 0xff) << 24);
    }

    StringBuilder microsecondString = new StringBuilder(Integer.toString(microseconds));
    while (microsecondString.length() < 6) {
      microsecondString.insert(0, "0");
    }
    boolean negative = (buf[pos] == 0x01);
    return (negative ? "-" : "") + (hourString + ":" + minuteString + ":" + secondString + "."
        + microsecondString);
  }
1314843
public BigDecimal get(JcNumber number) {
		Object val = this.getFor(number);
		if (val != null)
			return (BigDecimal)val;
		return null;
	}
149648
private BigDecimal convertValue(final Object value) {
		if (value == null) {
			return null;
		} else if (value instanceof BigDecimal) {
			return (BigDecimal) value;
		}

		// Try and convert "String" value
		String dataString = value.toString();
		if (Util.empty(dataString)) {
			return null;
		}

		try {
			return new BigDecimal(dataString);
		} catch (NumberFormatException ex) {
			throw new SystemException(
					"Could not convert data of type " + value.getClass() + " with String value "
					+ dataString + " to BigDecimal", ex);
		}
	}
1316104
public int getInt(int columnIndex) {
		Object fieldValue = data[columnIndex];
		if (fieldValue == null) {
			return 0;
		}
		if (fieldValue instanceof Number) {
			return ((Number) fieldValue).intValue();
		}
		throw new DBFException("Unsupported type for Number at column:" + columnIndex + " "
				+ fieldValue.getClass().getCanonicalName());
	}