Re: setBoolean and char/varchar

Поиск
Список
Период
Сортировка
От Barry Lind
Тема Re: setBoolean and char/varchar
Дата
Msg-id 3C4651D0.3090809@xythos.com
обсуждение исходный текст
Ответ на setBoolean and char/varchar  ("Paulo Merson" <paulo@summa-tech.com>)
Список pgsql-jdbc
Paulo,

No this isn't a bug, but the intended behavior.  The client (jdbc in
this case) doesn't know the ultimate datatype of any particular bind
variable.  That is only dertermined later when the server parses the SQL
statement.  Therefore the client relies on the application to tell it
what the datatype is.  Thus when you say setBoolean() you are saying
that the datatype is boolean not varchar.  Based on the datatype you say
then the client can build the correct SQL statement. (The client needs
to know whether to send  '...set foo = false...' or '...set foo = '0'...'.)

In the get case there is a little more flexibility since the client is
told by the server what the datatype of the value is (and the server
certainly knows this information).

thanks,
--Barry


Paulo Merson wrote:

> If you store '0' and '1' in a varchar(1) or char(1) column, you can read
> false and true respectively using ResultSet.getBoolean. This is great,
> especially if you are migrating from an Oracle database (shamefully
> Oracle doesn't have a Boolean data type).
>
> However, if you try to use PreparedStatement.setBoolean to set a value
> used in the "where" clause to compare to that '0'-or-'1' varchar(1) or
> char(1) column, then your select returns nothing.
>
> Isn't this behavior inconsistent between getBoolean and setBoolean? Is
> this a bug?
>
> (Oracle jdbc driver does allow getBoolean and setBoolean with char(1)
> and varchar2(1) consistently).
>
> Thanks,
>
> Paulo Merson
> Summa Technologies - www.summa-tech.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>



В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Thomas O'Dowd"
Дата:
Сообщение: Re: Problem in ResultSet#getTimestamp() of 7.2b4
Следующее
От: Jeroen van Vianen
Дата:
Сообщение: Re: Problem with getImportedKeys / getExportedKeys