From: Benjamin R. <ben...@co...> - 2002-04-08 11:57:02
|
Hi Steve I am doing the test on some code that is supposed to take a result set and "do the right thing" with it. As it happens, it always uses getString, but that might change; and the database will actually return a result set with a boolean in it, not a string, in the case being tested. It seems unfortunate to build into the test an unnecessary dependency on the way the code I'm testing happens to work; especially when the fix is so simple. In other words, putting "false" (or better, "new Boolean(false).toString()") in the MockResultSet rather than "new Boolean(false)" feels like a hack to me. I'm not being modest so much as cautious: the Javadoc for java 1.2.2 (which I'm using, alas) defines getString as "Gets the value of a column in the current row as a Java String." Which is a little ambiguous -- maybe implementations even differ! But the setup we use -- jdk1.2.2, Oracle thin drivers -- works the way I describe. cheers Ben > Thanks for the prompt. We'll take a look (unless you're being > modest and know that this fix should really be made). > > One thought, though, is it likely that you would write code > that gets both the string and the other type? If not, you > could always set 'aBoolean" to be "false" yourself. Has this > actually been a problem for you, or are you concerned about > conforming to the spec? > > Steve > > > ----- Original Message ----- > From: "Benjamin Rosenbaum" <ben...@co...> > To: <moc...@li...> > Sent: Tuesday, April 02, 2002 3:26 PM > Subject: [MO-java-dev] Question about MockResultSet.getString > > > > > > Hi all > > > > My impression is that java.sql.ResultSet.getString(...) gives you a > > String representation even if the datatype is not a String (that is, > it > > tries to do a conversion for you). > > > > Currently if you do: > > > > String columns[] = { "aString", "anInt", "aBoolean", > "aDouble" }; > > Object values[] = { "FOO", new Integer(123), new > Boolean(false), > > new Double(0.02) }; > > > > ResultSet rset = new MockSingleRowResultSet(columns, values); > > > > return rset.getString("aBoolean"); > > > > You get an exception. Is this the correct behavior? |