agora inbox for pljava-dev@postgresql.org
help / color / mirror / Atom feedSubject: [Pljava-dev] ResultSet getString
Date: Thu, 18 May 2006 15:31:42 +0200
Message-ID: <446C773E.6000102@lewczuk.com> (raw)
In-Reply-To: <446C69C8.3030908@tada.se>
References: <446C5033.2000508@lewczuk.com>
<446C55FE.2020902@tada.se>
<e4hmi1$9o3$1@sea.gmane.org>
<446C69C8.3030908@tada.se>
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
view thread (10+ messages) latest in thread
Message-ID: <446C773E.6000102@lewczuk.com>
Permalink: ../446C773E.6000102@lewczuk.com/
Also on: postgresql.org/message-id/446C773E.6000102@lewczuk.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pljava-dev@postgresql.org
Subject: Re: [Pljava-dev] ResultSet getString
In-Reply-To: <446C773E.6000102@lewczuk.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox