Thomas Kellerer schrieb am 28.07.2016 um 22:24:
> Vladimir Sitnikov schrieb am 27.07.2016 um 21:58:
>>
>> I think something similar is needed for PgPreparedStatement as well, but I did not find a way to check
>> the type of a column the way it's done in PgResultSet. It seems that ParameterList.getTypeOIDs()
>> would provide that information, but I don't know how to use that. If someone points me in the right
>> direction I can add that as well.
>>
>>
>> I'm not yet ready to answer that.
>>
>
> It would be nice if someone else could point me in the right direction, because I think
> that only a change to PreparedStatement would make that complete.
>
I wonder if something like this would be correct to detect the column type in PgPreparedStatement:
private boolean isBytea(int i) throws SQLException {
TypeInfo info = connection.getTypeInfo();
int columnOID = preparedParameters.getTypeOIDs()[i];
String pgType = info.getPGType(columnOID);
return "bytea".equals(pgType);
}
private boolean isVarchar(int i) throws SQLException {
TypeInfo info = connection.getTypeInfo();
int columnOID = preparedParameters.getTypeOIDs()[i];
String pgType = info.getPGType(columnOID);
return "text".equals(pgType) ||
"varchar".equals(pgType) ||
"character varying".equals(pgType) ||
"char".equals(pgType);
}
I chose to compare the Postgres Names rather than the java.sql.Type constants because it seems
that TypeInfoCache will send a SQL query to the backend (at least once) to get that mapping.
I am not sure if "character varying" will ever be needed. TypeInfoCache does not have that in its internal array
where oids are mapped to type names.
and then in the setClob() method:
if (isVarchar(i)) {
setString(i, x.getSubString(1, (int)x.length()));
return;
}
and for setBlob() the similar thing:
if (isBytea(i)) {
setBytes(i, x.getBytes(1, (int)x.length()));
return;
}