PDA

View Full Version : ValueInteger



JGunderson
02-08-2006, 01:45 PM
Hi,


I'm writing a tranformation plugin and am having trouble with ValueInteger. I'm adding a new field to a row like this:



r.addValue(new Value("inv_week", i));



where i is an int. I believe this would create a new ValueInteger.



When the next step runs it complains that inv_week is not set. The problem does not occur if I cast to long:



r.addValue(new Value("inv_week", (long)i));



Am I using Value correctly or is there a problem with using int?



Thx, Jeff

MattCasters
02-08-2006, 02:06 PM
Jeff,

The constructor Value(String, int) is to create an empty value (null) with a certain data type.
Like this:

Value value1 = new Value("name", Value.VALUE_TYPE_STRING);
Value value2 = new Value("id", Value.VALUE_TYPE_INTEGER);

If you want to set an int, byte, long, ... value use:

value1.setValue("Jeff");
value2.setValue(5);

Please note that you can change data types like this:

value1.setValue(5) turning value1 into an Integer.
This data type change is automatic, just like this.

String name = value1.getString(); // "Jeff"
String strId = value2.getString(); // "5"

HTH,

Matt

kettle_anonymous
02-09-2006, 04:51 AM
OK, I got it Matt. I'm just using the constructor wrong.
Thx, Jeff