how can I recover from truncate write?

Поиск
Список
Период
Сортировка
От Steve Pothier
Тема how can I recover from truncate write?
Дата
Msg-id 200211151655.gAFGtbG4030646@payson.tucson.saic.com
обсуждение исходный текст
Список pgsql-jdbc
If I attempt to write a field to the DB that is too long, I get an
SQLException (not SQLWarning, not DataTrunctation).  The INSERT
apparently fails.  I'ld like to issue a warning and automatically
truncate to fit.  Given that I only get a general SQLException,
PROGRAMATICALLY its difficult to know that I got a data truncation (as
opposed to other exception) and if truncation, its difficult to know
how long the field is allowed to be (or even which field failed).

SQLException.getMessage() yields: "value too long for type character
varying(20)"  so I COULD parse that message but that seems horrid.

Any better ideas?



The doc http://lab.applinet.nl/postgresql-jdbc/ discusses two
conflicting readings on what should happen with regard to data
truncation.  I just tried some tests and neither approaches work
(ie. the truncation is not reported by Statement.getWarnings(), and
is not thrown as an SQLWarning or DataTruncation exceptions).  I think
this means the driver is guaranteed to be wrong (and hard to use in
the face of truncations!)

The doc already warns that DataTruncation is never thrown. It does not
point out that Statement.getWarnings also does not work for data
truncation errors.


-Steve-

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

Предыдущее
От: Lloyd Meinholz
Дата:
Сообщение: Re: postgreSQL 7.2.3: jdbc compile problem
Следующее
От: "Felipe Schnack"
Дата:
Сообщение: default values in queries