Search in sources :

Example 6 with Procedure

use of org.h2.engine.Procedure in project h2database by h2database.

the class JdbcDatabaseMetaData method getProcedures.

/**
 * Gets the list of procedures. The result set is sorted by PROCEDURE_SCHEM,
 * PROCEDURE_NAME, and NUM_INPUT_PARAMS. There are potentially multiple
 * procedures with the same name, each with a different number of input
 * parameters.
 *
 * <ol>
 * <li>PROCEDURE_CAT (String) catalog</li>
 * <li>PROCEDURE_SCHEM (String) schema</li>
 * <li>PROCEDURE_NAME (String) name</li>
 * <li>NUM_INPUT_PARAMS (int) the number of arguments</li>
 * <li>NUM_OUTPUT_PARAMS (int) for future use, always 0</li>
 * <li>NUM_RESULT_SETS (int) for future use, always 0</li>
 * <li>REMARKS (String) description</li>
 * <li>PROCEDURE_TYPE (short) if this procedure returns a result
 * (procedureNoResult or procedureReturnsResult)</li>
 * <li>SPECIFIC_NAME (String) name</li>
 * </ol>
 *
 * @param catalogPattern null or the catalog name
 * @param schemaPattern null (to get all objects) or a schema name
 *            (uppercase for unquoted names)
 * @param procedureNamePattern the procedure name pattern
 * @return the procedures
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getProcedures(String catalogPattern, String schemaPattern, String procedureNamePattern) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getProcedures(" + quote(catalogPattern) + ", " + quote(schemaPattern) + ", " + quote(procedureNamePattern) + ");");
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "ALIAS_CATALOG PROCEDURE_CAT, " + "ALIAS_SCHEMA PROCEDURE_SCHEM, " + "ALIAS_NAME PROCEDURE_NAME, " + "COLUMN_COUNT NUM_INPUT_PARAMS, " + "ZERO() NUM_OUTPUT_PARAMS, " + "ZERO() NUM_RESULT_SETS, " + "REMARKS, " + "RETURNS_RESULT PROCEDURE_TYPE, " + "ALIAS_NAME SPECIFIC_NAME " + "FROM INFORMATION_SCHEMA.FUNCTION_ALIASES " + "WHERE ALIAS_CATALOG LIKE ? ESCAPE ? " + "AND ALIAS_SCHEMA LIKE ? ESCAPE ? " + "AND ALIAS_NAME LIKE ? ESCAPE ? " + "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, NUM_INPUT_PARAMS");
        prep.setString(1, getCatalogPattern(catalogPattern));
        prep.setString(2, "\\");
        prep.setString(3, getSchemaPattern(schemaPattern));
        prep.setString(4, "\\");
        prep.setString(5, getPattern(procedureNamePattern));
        prep.setString(6, "\\");
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 7 with Procedure

use of org.h2.engine.Procedure in project h2database by h2database.

the class JdbcDatabaseMetaData method getProcedureColumns.

/**
 * Gets the list of procedure columns. The result set is sorted by
 * PROCEDURE_SCHEM, PROCEDURE_NAME, NUM_INPUT_PARAMS, and POS.
 * There are potentially multiple procedures with the same name, each with a
 * different number of input parameters.
 *
 * <ol>
 * <li>PROCEDURE_CAT (String) catalog</li>
 * <li>PROCEDURE_SCHEM (String) schema</li>
 * <li>PROCEDURE_NAME (String) name</li>
 * <li>COLUMN_NAME (String) column name</li>
 * <li>COLUMN_TYPE (short) column type
 * (always DatabaseMetaData.procedureColumnIn)</li>
 * <li>DATA_TYPE (short) sql type</li>
 * <li>TYPE_NAME (String) type name</li>
 * <li>PRECISION (int) precision</li>
 * <li>LENGTH (int) length</li>
 * <li>SCALE (short) scale</li>
 * <li>RADIX (int) always 10</li>
 * <li>NULLABLE (short) nullable
 * (DatabaseMetaData.columnNoNulls for primitive data types,
 * DatabaseMetaData.columnNullable otherwise)</li>
 * <li>REMARKS (String) description</li>
 * <li>COLUMN_DEF (String) always null</li>
 * <li>SQL_DATA_TYPE (int) for future use, always 0</li>
 * <li>SQL_DATETIME_SUB (int) for future use, always 0</li>
 * <li>CHAR_OCTET_LENGTH (int) always null</li>
 * <li>ORDINAL_POSITION (int) the parameter index
 * starting from 1 (0 is the return value)</li>
 * <li>IS_NULLABLE (String) always "YES"</li>
 * <li>SPECIFIC_NAME (String) name</li>
 * </ol>
 *
 * @param catalogPattern null or the catalog name
 * @param schemaPattern null (to get all objects) or a schema name
 *            (uppercase for unquoted names)
 * @param procedureNamePattern the procedure name pattern
 * @param columnNamePattern the procedure name pattern
 * @return the procedure columns
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getProcedureColumns(String catalogPattern, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getProcedureColumns(" + quote(catalogPattern) + ", " + quote(schemaPattern) + ", " + quote(procedureNamePattern) + ", " + quote(columnNamePattern) + ");");
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "ALIAS_CATALOG PROCEDURE_CAT, " + "ALIAS_SCHEMA PROCEDURE_SCHEM, " + "ALIAS_NAME PROCEDURE_NAME, " + "COLUMN_NAME, " + "COLUMN_TYPE, " + "DATA_TYPE, " + "TYPE_NAME, " + "PRECISION, " + "PRECISION LENGTH, " + "SCALE, " + "RADIX, " + "NULLABLE, " + "REMARKS, " + "COLUMN_DEFAULT COLUMN_DEF, " + "ZERO() SQL_DATA_TYPE, " + "ZERO() SQL_DATETIME_SUB, " + "ZERO() CHAR_OCTET_LENGTH, " + "POS ORDINAL_POSITION, " + "? IS_NULLABLE, " + "ALIAS_NAME SPECIFIC_NAME " + "FROM INFORMATION_SCHEMA.FUNCTION_COLUMNS " + "WHERE ALIAS_CATALOG LIKE ? ESCAPE ? " + "AND ALIAS_SCHEMA LIKE ? ESCAPE ? " + "AND ALIAS_NAME LIKE ? ESCAPE ? " + "AND COLUMN_NAME LIKE ? ESCAPE ? " + "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, ORDINAL_POSITION");
        prep.setString(1, "YES");
        prep.setString(2, getCatalogPattern(catalogPattern));
        prep.setString(3, "\\");
        prep.setString(4, getSchemaPattern(schemaPattern));
        prep.setString(5, "\\");
        prep.setString(6, getPattern(procedureNamePattern));
        prep.setString(7, "\\");
        prep.setString(8, getPattern(columnNamePattern));
        prep.setString(9, "\\");
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Aggregations

SQLException (java.sql.SQLException)3 DbException (org.h2.message.DbException)3 PreparedStatement (java.sql.PreparedStatement)2 Bnf (org.h2.bnf.Bnf)2 DbContextRule (org.h2.bnf.context.DbContextRule)2 Procedure (org.h2.engine.Procedure)2 HashSet (java.util.HashSet)1 RuleElement (org.h2.bnf.RuleElement)1 RuleList (org.h2.bnf.RuleList)1 DbContents (org.h2.bnf.context.DbContents)1 DbProcedure (org.h2.bnf.context.DbProcedure)1 DbSchema (org.h2.bnf.context.DbSchema)1 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)1 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)1 AlterTableRenameConstraint (org.h2.command.ddl.AlterTableRenameConstraint)1 DeallocateProcedure (org.h2.command.ddl.DeallocateProcedure)1 PrepareProcedure (org.h2.command.ddl.PrepareProcedure)1 ExecuteProcedure (org.h2.command.dml.ExecuteProcedure)1 ValueString (org.h2.value.ValueString)1