public long getInternalLong(ColumnInformation columnInfo) throws SQLException {
    if (lastValueWasNull()) {
      return 0;
    }

    long value;
    switch (columnInfo.getColumnType()) {
      case BIT:
        return parseBit();
      case TINYINT:
        value = getInternalTinyInt(columnInfo);
        break;
      case SMALLINT:
      case YEAR:
        value = getInternalSmallInt(columnInfo);
        break;
      case INTEGER:
      case MEDIUMINT:
        value = getInternalMediumInt(columnInfo);
        break;
      case BIGINT:
        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 value;
        }
        BigInteger unsignedValue = 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});
        if (unsignedValue.compareTo(new BigInteger(String.valueOf(Long.MAX_VALUE))) > 0) {
          throw new SQLException(
              "Out of range value for column '" + columnInfo.getName() + "' : value "
                  + unsignedValue + " is not in Long range", "22003", 1264);
        }
        return unsignedValue.longValue();
      case FLOAT:
        Float floatValue = getInternalFloat(columnInfo);
        if (floatValue.compareTo((float) Long.MAX_VALUE) >= 1) {
          throw new SQLException(
              "Out of range value for column '" + columnInfo.getName() + "' : value " + floatValue
                  + " is not in Long range", "22003", 1264);
        }
        return floatValue.longValue();
      case DOUBLE:
        Double doubleValue = getInternalDouble(columnInfo);
        if (doubleValue.compareTo((double) Long.MAX_VALUE) >= 1) {
          throw new SQLException(
              "Out of range value for column '" + columnInfo.getName() + "' : value " + doubleValue
                  + " is not in Long range", "22003", 1264);
        }
        return doubleValue.longValue();
      case DECIMAL:
      case OLDDECIMAL:
        BigDecimal bigDecimal = getInternalBigDecimal(columnInfo);
        rangeCheck(Long.class, Long.MIN_VALUE, Long.MAX_VALUE, bigDecimal, columnInfo);
        return bigDecimal.longValue();
      case VARSTRING:
      case VARCHAR:
      case STRING:
        return Long.parseLong(new String(buf, pos, length, StandardCharsets.UTF_8));
      default:
        throw new SQLException(
            "getLong not available for data field type " + columnInfo.getColumnType()
                .getJavaTypeName());

    }
    rangeCheck(Long.class, Long.MIN_VALUE, Long.MAX_VALUE, value, columnInfo);
    return value;

  }
public long getInternalLong ( ColumnInformation columnInfo ) throws SQLException { if ( lastValueWasNull ( ) ) { return 0 ; } long value ; switch ( columnInfo . getColumnType ( ) ) { case BIT : return parseBit ( ) ; case TINYINT : value = getInternalTinyInt ( columnInfo ) ; break ; case SMALLINT : case YEAR : value = getInternalSmallInt ( columnInfo ) ; break ; case INTEGER : case MEDIUMINT : value = getInternalMediumInt ( columnInfo ) ; break ; case BIGINT : 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 value ; } BigInteger unsignedValue = 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 } ) ; if ( unsignedValue . compareTo ( new BigInteger ( String . valueOf ( Long . MAX_VALUE ) ) ) > 0 ) { throw new SQLException ( "Out of range value for column '" + columnInfo . getName ( ) + "' : value " + unsignedValue + " is not in Long range" , "22003" , 1264 ) ; } return unsignedValue . longValue ( ) ; case FLOAT : Float floatValue = getInternalFloat ( columnInfo ) ; if ( floatValue . compareTo ( ( float ) Long . MAX_VALUE ) >= 1 ) { throw new SQLException ( "Out of range value for column '" + columnInfo . getName ( ) + "' : value " + floatValue + " is not in Long range" , "22003" , 1264 ) ; } return floatValue . longValue ( ) ; case DOUBLE : Double doubleValue = getInternalDouble ( columnInfo ) ; if ( doubleValue . compareTo ( ( double ) Long . MAX_VALUE ) >= 1 ) { throw new SQLException ( "Out of range value for column '" + columnInfo . getName ( ) + "' : value " + doubleValue + " is not in Long range" , "22003" , 1264 ) ; } return doubleValue . longValue ( ) ; case DECIMAL : case OLDDECIMAL : BigDecimal bigDecimal = getInternalBigDecimal ( columnInfo ) ; rangeCheck ( Long . class , Long . MIN_VALUE , Long . MAX_VALUE , bigDecimal , columnInfo ) ; return bigDecimal . longValue ( ) ; case VARSTRING : case VARCHAR : case STRING : return Long . parseLong ( new String ( buf , pos , length , StandardCharsets . UTF_8 ) ) ; default : throw new SQLException ( "getLong not available for data field type " + columnInfo . getColumnType ( ) . getJavaTypeName ( ) ) ; } rangeCheck ( Long . class , Long . MIN_VALUE , Long . MAX_VALUE , value , columnInfo ) ; return value ; }
Get long from raw binary format.

@param columnInfo column information
@return long value
@throws SQLException if column is not numeric or is not in Long bounds (for big unsigned
values)