while (rs.next()) {
String schema = rs.getString("nspname");
String procedureName = rs.getString("proname");
String specificName = rs.getString("proname") + "_" + rs.getString("oid");
Type returnType = reg.loadType(rs.getInt("prorettype"));
String returnTypeType = rs.getString("typtype");
int returnTypeRelId = rs.getInt("typrelid");
Integer[] argTypeIds = rs.getObject("proargtypes", Integer[].class);
String[] argNames = rs.getObject("proargnames", String[].class);
String[] argModes = rs.getObject("proargmodes", String[].class);
Integer[] allArgTypeIds = rs.getObject("proallargtypes", Integer[].class);
int numArgs = allArgTypeIds != null ? allArgTypeIds.length : argTypeIds.length;
// decide if we are returning a single column result.
if (returnTypeType.equals("b") ||
returnTypeType.equals("d") ||
(returnTypeType.equals("p") && argModes == null)) {
Object[] row = new Object[resultFields.length];
row[0] = null;
row[1] = schema;
row[2] = procedureName;
row[3] = "returnValue";
row[4] = DatabaseMetaData.procedureColumnReturn;
row[5] = SQLTypeMetaData.getSQLType(returnType);
row[6] = SQLTypeMetaData.getTypeName(returnType, null, 0);
row[7] = null;
row[8] = null;
row[9] = null;
row[10] = null;
row[11] = DatabaseMetaData.procedureNullableUnknown;
row[12] = null;
row[17] = 0;
row[18] = "";
row[19] = specificName;
results.add(row);
}
// Add a row for each argument.
for (int i = 0; i < numArgs; i++) {
Object[] row = new Object[resultFields.length];
row[0] = null;
row[1] = schema;
row[2] = procedureName;
if (argNames != null) {
row[3] = argNames[i];
}
else {
row[3] = "$" + (i + 1);
}
int columnMode = DatabaseMetaData.procedureColumnIn;
if (argModes != null) {
if (argModes[i].equals("o")) {
columnMode = DatabaseMetaData.procedureColumnOut;
}
else if (argModes[i].equals("b")) {
columnMode = DatabaseMetaData.procedureColumnInOut;
}
}
row[4] = columnMode;
Type argType;
if (allArgTypeIds != null) {
argType = reg.loadType(allArgTypeIds[i].intValue());
}
else {
argType = reg.loadType(argTypeIds[i].intValue());
}
row[5] = SQLTypeMetaData.getSQLType(argType);
row[6] = argType.getJavaType(argType.getPreferredFormat(), connection.getTypeMap()).getName();
row[7] = null;
row[8] = null;
row[9] = null;
row[10] = null;
row[11] = DatabaseMetaData.procedureNullableUnknown;
row[12] = null;
row[17] = i + 1;
row[18] = "";
row[19] = specificName;
results.add(row);
}
// if we are returning a multi-column result.
if (returnTypeType.equals("c") ||
(returnTypeType.equals("p") && argModes != null && returnTypeRelId != 0)) {
String columnsql = "SELECT a.attname,a.atttypid FROM pg_catalog.pg_attribute a WHERE a.attrelid = " + returnTypeRelId + " AND a.attnum > 0 ORDER BY a.attnum ";
try (ResultSet columnrs = connection.createStatement().executeQuery(columnsql)) {
while (columnrs.next()) {
Type columnType = reg.loadType(columnrs.getInt("atttypid"));
Object[] row = new Object[resultFields.length];
row[0] = null;
row[1] = schema;
row[2] = procedureName;
row[3] = columnrs.getString("attname");
row[4] = DatabaseMetaData.procedureColumnResult;
row[5] = SQLTypeMetaData.getSQLType(columnType);
row[6] = columnType.getJavaType(columnType.getPreferredFormat(), connection.getTypeMap()).getName();
row[7] = null;
row[8] = null;
row[9] = null;
row[10] = null;
row[11] = DatabaseMetaData.procedureNullableUnknown;