private String toStringString( boolean pad ) {
    String retval = null;

    if ( value == null ) {
      return null;
    }

    if ( value.getLength() <= 0 ) {
      // No length specified!
      if ( isNull() || value.getString() == null ) {
        retval = Const.NULL_STRING;
      } else {
        retval = value.getString();
      }
    } else {
      if ( pad ) {
        StringBuilder ret = null;

        if ( isNull() || value.getString() == null ) {
          ret = new StringBuilder( Const.NULL_STRING );
        } else {
          ret = new StringBuilder( value.getString() );
        }

        int length = value.getLength();
        if ( length > 16384 ) {
          length = 16384; // otherwise we get OUT OF MEMORY errors for CLOBS.
        }
        Const.rightPad( ret, length );

        retval = ret.toString();
      } else {
        if ( isNull() || value.getString() == null ) {
          retval = Const.NULL_STRING;
        } else {
          retval = value.getString();
        }
      }
    }
    return retval;
  }
@Test
  public void testToStringString() {
    String result = null;

    Value vs = new Value( "Name", Value.VALUE_TYPE_STRING );
    vs.setValue( "test string" );
    result = vs.toString( true );
    assertEquals( "test string", result );

    vs.setLength( 20 );
    result = vs.toString( true ); // padding
    assertEquals( "test string         ", result );

    vs.setLength( 4 );
    result = vs.toString( true ); // truncate
    assertEquals( "test", result );

    vs.setLength( 0 );
    result = vs.toString( true ); // on 0 => full string
    assertEquals( "test string", result );

    // no padding
    result = vs.toString( false );
    assertEquals( "test string", result );

    vs.setLength( 20 );
    result = vs.toString( false );
    assertEquals( "test string", result );

    vs.setLength( 4 );
    result = vs.toString( false );
    assertEquals( "test string", result );

    vs.setLength( 0 );
    result = vs.toString( false );
    assertEquals( "test string", result );

    vs.setLength( 4 );
    vs.setNull();
    result = vs.toString( false );
    assertEquals( "", result );

    Value vs1 = new Value( "Name", Value.VALUE_TYPE_STRING );
    assertEquals( "", vs1.toString() );

    // Just to get 100% coverage
    Value vs2 = new Value( "Name", Value.VALUE_TYPE_NONE );
    assertEquals( "", vs2.toString() );
  }