Re: Custom type woes

Поиск
Список
Период
Сортировка
От Kris Jurka
Тема Re: Custom type woes
Дата
Msg-id Pine.BSO.4.63.0606301459170.29530@leary2.csoft.net
обсуждение исходный текст
Ответ на Re: Custom type woes  (CG <cgg007@yahoo.com>)
Список pgsql-jdbc

On Fri, 30 Jun 2006, CG wrote:

> It still generated the "must use explicit cast" error on insert. My
> inexperience with jdbc really shows here. I must not have hooked in the new
> class in all the spots where it should be hooked. I created a
> PGuniqueidentifier.class with appropriate member data, constructors, and
> methods setValue, equals, clone, and getValue. I then hooked it in under
> org.postgresql.jdbc2.AbstractJdbc2Connection#initObjectTypes by adding the line
> addDataType("uniqueidentifier", org.postgresql.util.PGuniqueidentifier.class);
> I must be leaving something out.

The key thing you need to do is call setObject like so:

ps.setObject(1, new PGuniqueidentifier("stringdata"));

This is how it determines the type you're passing in.

>> It will still do that regardless of what you do.  What java.sql.Type would
>> you like it to use and how could it know that?
>
> Like MONEY uses double, I was hoping to map uniqueidentifier to VARCHAR... It
> wouldn't know unless someone told it. :) Perhaps putting something in under
> org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData#getColumns ? That also may
> be the wrong course of action.

For the moment all of the mappings to java.sql.Type values are hardcoded
in org.postgresql.jdbc2.TypeInfoCache and money happens to have an entry
for historical reasons, but no other extension type does.

If you really want it to operate exactly like text the easiest thing to do
is just make it a text entry (possibly a domain on text) in the database.
Yes, you'll waste some storage space, but perhaps that is acceptable.

Kris Jurka

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

Предыдущее
От: CG
Дата:
Сообщение: Re: Custom type woes
Следующее
От: Luis Vilar Flores
Дата:
Сообщение: Re: bytea memory improvement