Daniel John Debrunner <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] wrote:
>
>> While working on DERBY-925 and DERBY-969, I need to get information
>> about the types of the procedure/function parameters. Specifically I
>> need to fill the COLUMN_DEF (Default value for the parameter, if any)
>> and CHAR_OCTET_LENGTH (Byte length of char/binary types, NULL for
>> other types) columns.
>>
>> So given type T, how do I
>>
>> 1) Find out if T is character or binary?
>> 2) What the maximum length of T is, if char/binary?
>> 3) If T has a default value?
>> 4) If T's default value is NULL?
>> 5) If T's value cannot be represented without truncation?
>>
> [snip]
>>
>> So how can/should I use this to get the information I need? If I need
>> to add information, where do I add it?
>
> Just commenting on DERBY-925, I couldn't see how 969 related to types.
Well, DERBY-969 the closest thing to a JIRA issue for adding
JDBC 4.0 functionality to getProcedureColumns(). The work covered by
DERBY-969, as it stands, is too much for a single JIRA issue IMHO.
Since it is already a sub-task, JIRA will not let me create new
sub-tasks under it...
>
> Are you baseing your work on
> org.apache.derby.catalog.GetProcedureColumns, because that probably
> hanldes most of the cases you require.
Yes, that's my plan.
>
> The javadoc for the org.apache.derby.iapi.types package may provide some
> background.
I'm looking at it :)
> A routine is partially described by
>
> org.apache.derby.catalog.types.RoutineAliasInfo
>
> That has methods
>
> public TypeDescriptor[] getParameterTypes()
> public public TypeDescriptor getReturnType()
>
> TypeDescriptor represents a type in the catalogs, it's best to create an
> instance of the runtime type descriptor DataTypeDescriptor from it.
>
> TypeDescriptor td; // get from array/method
>
> // TypeId represents the fixed aspect of a type, without
> // nullability or any length attributes.
> TypeId typeId = TypeId.getBuiltInTypeId(td.getJDBCTypeId());
>
> DataTypeDescriptor dtd = new DataTypeDescriptor(typeId,
> td.getPrecision(), td.getScale(), td.isNullable(), td.getMaximumWidth());
>
> I think the above block of code should be made into a utility method in
> DataTypeDescriptor, but it's not there yet.
>
> Anyway DataTypeDescriptor has all the methods you need, some may hang
> off the TypeId returned by getTypeId.
>
Thanks, that helps. One question though. In GetProcedureColumns I now
have the following (sqlType is the TypeDescriptor from RoutineAliasInfo):
case CHAR_OCTET_LENGTH:
if (sqlType != null) {
int type = sqlType.getJDBCTypeId();
if (DataTypeDescriptor.isCharacterType(type) ||
DataTypeDescriptor.isBinaryType(type)) {
return sqlType.getMaximumWidthInBytes();
}
}
return 0; // FIXME must be converted to SQL NULL in
query
But this fails to compile because DataTypeDescriptor.isCharacterType
and DataTypeDescriptor.isBinaryType are private.
[javac]
/private/tmp/DERBY/derby-969/java/engine/org/apache/derby/catalog/GetProcedureColumns.java:289:
isCharacterType(int) has private access in
org.apache.derby.iapi.types.DataTypeDescriptor
[javac] if
(DataTypeDescriptor.isCharacterType(type) ||
[javac] ^
[javac]
/private/tmp/DERBY/derby-969/java/engine/org/apache/derby/catalog/GetProcedureColumns.java:290:
isBinaryType(int) has private access in
org.apache.derby.iapi.types.DataTypeDescriptor
[javac]
DataTypeDescriptor.isBinaryType(type)) {
Is that intentional? Would it be ok to make them more accessible?
> Function parameters and return types do not have defaults.
OK.
COLUMN_DEF is only part of getProcedureColumns in
JDBC 4.0. So there is no COLUMN_DEF in the result set from
getFunctionParameters().
>
> Not sure about the truncation question, what's doing the truncation,
> what do you mean value of T?
This comes from the JDBC 4.0 javadoc for getProcedureColumns():
# COLUMN_DEF String => The default column value.
* The string NULL (not enclosed in quotes) - If NULL was specified as the
default value
* TRUNCATE (not enclosed in quotes) - If the specified default value cannot
be represented without truncation
* NULL - If a default value was not specified
>
> Hope this helps,
Yes, it does, thank you.
--
dt