提交 f3786d43 authored 作者: Thomas Mueller's avatar Thomas Mueller

DatabaseMetaData.getProcedureColumns returned the wrong data (it also returned…

DatabaseMetaData.getProcedureColumns returned the wrong data (it also returned the Connection parameter if there was any).
上级 cdb36815
......@@ -581,14 +581,17 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* <li>2 PROCEDURE_SCHEM (String) schema </li>
* <li>3 PROCEDURE_NAME (String) name </li>
* <li>4 COLUMN_NAME (String) column name </li>
* <li>5 COLUMN_TYPE (short) column type </li>
* <li>5 COLUMN_TYPE (short) column type
* (always DatabaseMetaData.procedureColumnIn)</li>
* <li>6 DATA_TYPE (short) sql type </li>
* <li>7 TYPE_NAME (String) type name </li>
* <li>8 PRECISION (int) precision </li>
* <li>9 LENGTH (int) length </li>
* <li>10 SCALE (short) scale </li>
* <li>11 RADIX (int) always 10 </li>
* <li>12 NULLABLE (short) nullable </li>
* <li>12 NULLABLE (short) nullable
* (DatabaseMetaData.columnNoNulls for primitive data types,
* DatabaseMetaData.columnNullable otherwise)</li>
* <li>13 REMARKS (String) description </li>
* <li>14 COLUMN_DEF (String) always null </li>
* <li>15 SQL_DATA_TYPE (int) for future use, always 0 </li>
......
......@@ -1078,7 +1078,7 @@ public class MetaTable extends Table {
// DATA_TYPE
"" + DataType.convertTypeToSQLType(method.getDataType()),
// COLUMN_COUNT INT
"" + method.getColumnClasses().length,
"" + method.getParameterCount(),
// RETURNS_RESULT SMALLINT
"" + returnsResult,
// REMARKS
......@@ -1127,6 +1127,9 @@ public class MetaTable extends Table {
for (FunctionAlias.JavaMethod method : alias.getJavaMethods()) {
Class<?>[] columnList = method.getColumnClasses();
for (int k = 0; k < columnList.length; k++) {
if (method.hasConnectionParam() && k == 0) {
continue;
}
Class<?> clazz = columnList[k];
int dataType = DataType.getTypeFromClass(clazz);
DataType dt = DataType.getDataType(dataType);
......@@ -1146,15 +1149,15 @@ public class MetaTable extends Table {
// COLUMN_COUNT
"" + method.getParameterCount(),
// POS INT
"" + k,
"" + (k + (method.hasConnectionParam() ? 0 : 1)),
// COLUMN_NAME
"P" + (k+1),
"P" + (k + 1),
// DATA_TYPE
"" + DataType.convertTypeToSQLType(dt.type),
// TYPE_NAME
dt.name,
// PRECISION
"" + dt.defaultPrecision,
// PRECISION INT
"" + MathUtils.convertLongToInt(dt.defaultPrecision),
// SCALE
"" + dt.defaultScale,
// RADIX
......
......@@ -258,6 +258,29 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals(10.0, rs.getDouble(2));
assertEquals(15.0, rs.getDouble(3));
DatabaseMetaData meta = conn.getMetaData();
rs = meta.getProcedureColumns(null, null, "MEAN2", null);
assertTrue(rs.next());
assertEquals("FUNCTIONS", rs.getString("PROCEDURE_CAT"));
assertEquals("PUBLIC", rs.getString("PROCEDURE_SCHEM"));
assertEquals("MEAN2", rs.getString("PROCEDURE_NAME"));
assertEquals("P2", rs.getString("COLUMN_NAME"));
assertEquals(DatabaseMetaData.procedureColumnIn, rs.getInt("COLUMN_TYPE"));
assertEquals("OTHER", rs.getString("TYPE_NAME"));
assertEquals(Integer.MAX_VALUE, rs.getInt("PRECISION"));
assertEquals(Integer.MAX_VALUE, rs.getInt("LENGTH"));
assertEquals(0, rs.getInt("SCALE"));
assertEquals(DatabaseMetaData.columnNullable, rs.getInt("NULLABLE"));
assertEquals("", rs.getString("REMARKS"));
assertEquals(null, rs.getString("COLUMN_DEF"));
assertEquals(0, rs.getInt("SQL_DATA_TYPE"));
assertEquals(0, rs.getInt("SQL_DATETIME_SUB"));
assertEquals(0, rs.getInt("CHAR_OCTET_LENGTH"));
assertEquals(1, rs.getInt("ORDINAL_POSITION"));
assertEquals("YES", rs.getString("IS_NULLABLE"));
assertEquals("MEAN2", rs.getString("SPECIFIC_NAME"));
assertFalse(rs.next());
stat.execute("CREATE ALIAS printMean FOR \"" +
getClass().getName() + ".printMean\"");
rs = stat.executeQuery(
......@@ -379,6 +402,32 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
DatabaseMetaData meta = conn.getMetaData();
rs = meta.getProcedureColumns(null, null, "ADD_ROW", null);
assertTrue(rs.next());
assertEquals("FUNCTIONS", rs.getString("PROCEDURE_CAT"));
assertEquals("PUBLIC", rs.getString("PROCEDURE_SCHEM"));
assertEquals("ADD_ROW", rs.getString("PROCEDURE_NAME"));
assertEquals("P2", rs.getString("COLUMN_NAME"));
assertEquals(DatabaseMetaData.procedureColumnIn, rs.getInt("COLUMN_TYPE"));
assertEquals("INTEGER", rs.getString("TYPE_NAME"));
assertEquals(10, rs.getInt("PRECISION"));
assertEquals(10, rs.getInt("LENGTH"));
assertEquals(0, rs.getInt("SCALE"));
assertEquals(DatabaseMetaData.columnNoNulls, rs.getInt("NULLABLE"));
assertEquals("", rs.getString("REMARKS"));
assertEquals(null, rs.getString("COLUMN_DEF"));
assertEquals(0, rs.getInt("SQL_DATA_TYPE"));
assertEquals(0, rs.getInt("SQL_DATETIME_SUB"));
assertEquals(0, rs.getInt("CHAR_OCTET_LENGTH"));
assertEquals(1, rs.getInt("ORDINAL_POSITION"));
assertEquals("YES", rs.getString("IS_NULLABLE"));
assertEquals("ADD_ROW", rs.getString("SPECIFIC_NAME"));
assertTrue(rs.next());
assertEquals("P3", rs.getString("COLUMN_NAME"));
assertEquals("VARCHAR", rs.getString("TYPE_NAME"));
assertFalse(rs.next());
stat.executeQuery("CALL ADD_ROW(2, 'World')");
stat.execute("CREATE ALIAS SELECT_F FOR \"" + getClass().getName() + ".select\"");
......@@ -491,6 +540,21 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals(null, rs.getString(1));
assertFalse(rs.next());
rs = meta.getProcedures(null, null, "NULL_RESULT");
rs.next();
assertEquals("FUNCTIONS", rs.getString("PROCEDURE_CAT"));
assertEquals("PUBLIC", rs.getString("PROCEDURE_SCHEM"));
assertEquals("NULL_RESULT", rs.getString("PROCEDURE_NAME"));
assertEquals(0, rs.getInt("NUM_INPUT_PARAMS"));
assertEquals(0, rs.getInt("NUM_OUTPUT_PARAMS"));
assertEquals(0, rs.getInt("NUM_RESULT_SETS"));
assertEquals("", rs.getString("REMARKS"));
assertEquals(DatabaseMetaData.procedureReturnsResult, rs.getInt("PROCEDURE_TYPE"));
assertEquals("NULL_RESULT", rs.getString("SPECIFIC_NAME"));
rs = meta.getProcedureColumns(null, null, "NULL_RESULT", null);
assertFalse(rs.next());
stat.execute("CREATE ALIAS RESULT_WITH_NULL FOR \"" + getClass().getName() + ".resultSetWithNull\"");
rs = stat.executeQuery("CALL RESULT_WITH_NULL()");
assertEquals(1, rs.getMetaData().getColumnCount());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论