From: | marek at lewczuk(dot)com (Marek Lewczuk) |
---|---|
To: | |
Subject: | [Pljava-dev] ResultSet getString |
Date: | 2006-05-18 13:31:42 |
Message-ID: | 446C773E.6000102@lewczuk.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pljava-dev |
Thomas Hallgren napisa?(a):
> Marek Lewczuk wrote:
> I see what you mean. Question is, what string representation should be
> used? What is more intuitive? Using the Java 'toString()' representation
> of an object or the PostgreSQL String representation of the SQL type?
>
> A typical Java developer who's not fluent in PostgreSQL type coercion
> would expect that ResultSet.getString() on a boolean would return "true"
> or "false", i.e. something that can be passed to Boolean.valueOf(String)
> and that Array types would follow the format stipulated by
> java.util.Arrays.toString(<type>[]) family of methods.
>
> At present, the getString() method will coerce basic types to strings
> using Java semantics. Arrays are not coerced though, since that
> functionality was introduced in Java 1.
Lets see what Java api say about ResultSet.getString():
"Retrieves the value of the designated column in the current row of this
ResultSet object as a String in the Java programming language."
It doesn't say, that getString() will return "a string representation of
the object". Now, if I would like to get PostgreSQL String
representation of multi-dimensional array, what method should I use ?
For me obvious thing to do is to call getString() and I wouldn't expect
that this will return same as ResultSet.getBoolean().toString(). Another
example:
Statement statement = ...
statement.execute()...
ResultSet result = ...
while (result.next()) {
// result contains 3 columns: varchar[], boolean, integer[]
// we create a duplicated row, without worrying about the SQL type
Statement s = connection.createStatement();
s.executeUpdate("INSERT ... (c1, c2, c3) VALUES ('" +
result.getString(0) + "', '" + result.getString(1) + "', '" +
result.getString(2) + "')");
}
My opinion is that you should keep getString() as a method to get
PostgreSQL string representation - this will keep compatibility with
previous pljava versions.
ML
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Hallgren | 2006-05-18 14:29:14 | [Pljava-dev] ResultSet getString |
Previous Message | Thomas Hallgren | 2006-05-18 12:34:16 | [Pljava-dev] ResultSet getString |