Java Code Examples for java.sql.DatabaseMetaData#getFunctions()

The following examples show how to use java.sql.DatabaseMetaData#getFunctions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaDataRegressionTest.java    From r-course with MIT License 6 votes vote down vote up
private void checkGetFunctionsForBug69298(String stepDescription, Connection testConn) throws Exception {
    DatabaseMetaData testDbMetaData = testConn.getMetaData();
    ResultSet functionsMD = testDbMetaData.getFunctions(null, null, "testBug69298_%");
    String sd = stepDescription + " getFunctions() ";

    assertTrue(sd + "one row expected.", functionsMD.next());

    // function: testBug69298_func
    assertEquals(sd + "-> FUNCTION_CAT", testConn.getCatalog(), functionsMD.getString("FUNCTION_CAT"));
    assertEquals(sd + "-> FUNCTION_SCHEM", null, functionsMD.getString("FUNCTION_SCHEM"));
    assertEquals(sd + "-> FUNCTION_NAME", "testBug69298_func", functionsMD.getString("FUNCTION_NAME"));
    assertEquals(sd + "-> REMARKS", "testBug69298_func comment", functionsMD.getString("REMARKS"));
    assertEquals(sd + "-> FUNCTION_TYPE", DatabaseMetaData.functionNoTable, functionsMD.getShort("FUNCTION_TYPE"));
    assertEquals(sd + "-> SPECIFIC_NAME", "testBug69298_func", functionsMD.getString("SPECIFIC_NAME"));

    assertFalse(stepDescription + "no more rows expected.", functionsMD.next());
}
 
Example 2
Source File: MetaDataRegressionTest.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
private void checkGetFunctionsForBug69298(String stepDescription, Connection testConn) throws Exception {
    DatabaseMetaData testDbMetaData = testConn.getMetaData();
    ResultSet functionsMD = testDbMetaData.getFunctions(null, null, "testBug69298_%");
    String sd = stepDescription + " getFunctions() ";

    assertTrue(sd + "one row expected.", functionsMD.next());

    // function: testBug69298_func
    assertEquals(sd + "-> FUNCTION_CAT", testConn.getCatalog(), functionsMD.getString("FUNCTION_CAT"));
    assertEquals(sd + "-> FUNCTION_SCHEM", null, functionsMD.getString("FUNCTION_SCHEM"));
    assertEquals(sd + "-> FUNCTION_NAME", "testBug69298_func", functionsMD.getString("FUNCTION_NAME"));
    assertEquals(sd + "-> REMARKS", "testBug69298_func comment", functionsMD.getString("REMARKS"));
    assertEquals(sd + "-> FUNCTION_TYPE", DatabaseMetaData.functionNoTable, functionsMD.getShort("FUNCTION_TYPE"));
    assertEquals(sd + "-> SPECIFIC_NAME", "testBug69298_func", functionsMD.getString("SPECIFIC_NAME"));

    assertFalse(stepDescription + "no more rows expected.", functionsMD.next());
}
 
Example 3
Source File: Show.java    From jsqsh with Apache License 2.0 6 votes vote down vote up
private ResultSet doFunctions(Session session, Connection con, Options options)
    throws SQLException {
    
    if (options.arguments.size() > 2) {
        
        session.err.println("Use: \\show functions [[[catalog.]schema-pattern.]func-pattern]");
        return null;
    }
    
    if (options.essential) {
        
        options.columns = essentialFunctionCols;
    }
    
    SQLConnectionContext ctx = (SQLConnectionContext) session.getConnectionContext();
    SQLObjectName name =
        (options.arguments.size() == 2) ? new SQLObjectName(ctx, options.arguments.get(1))
            : new SQLObjectName(ctx, "%");
    
    DatabaseMetaData meta = con.getMetaData();
    return meta.getFunctions(
        (options.catalog != null ? options.catalog : name.getCatalog()),
        (options.schemaPattern != null ? options.schemaPattern : name.getSchema()),
        (options.tablePattern != null ? options.tablePattern : name.getName()));
}
 
Example 4
Source File: MetadataUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Call {@link DatabaseMetaData#geFunctions(String, String, String)},
 * wrapping any internal runtime exception into an {@link SQLException}.
 */
public static ResultSet getFunctions(DatabaseMetaData dmd,
        String catalog, String schemaPattern, String functionNamePattern)
        throws SQLException {
    try {
        return dmd.getFunctions(catalog, schemaPattern,
                functionNamePattern);
    } catch (SQLException e) {
        throw e;
    } catch (Throwable t) {
        throw new SQLException(t);
    }
}
 
Example 5
Source File: TestDatabaseMetaData.java    From evosql with Apache License 2.0 5 votes vote down vote up
/**
 * Basic test of DatabaseMetaData functions that access system tables
 */
public void testTwo() throws Exception {

    Connection conn = newConnection();
    int        updateCount;

    try {
        TestUtil.testScript(conn, "testrun/hsqldb/TestSelf.txt");

        DatabaseMetaData dbmeta = conn.getMetaData();

        dbmeta.allProceduresAreCallable();
        dbmeta.getBestRowIdentifier(null, null, "T_1",
                                    DatabaseMetaData.bestRowTransaction,
                                    true);
        dbmeta.getCatalogs();
        dbmeta.getColumnPrivileges(null, "PUBLIC", "T_1", "%");
        dbmeta.getColumns("PUBLIC", "PUBLIC", "T_1", "%");
        dbmeta.getCrossReference(null, null, "T_1", null, null, "T_1");
        dbmeta.getExportedKeys(null, null, "T_1");
        dbmeta.getFunctionColumns(null, "%", "%", "%");
        dbmeta.getFunctions(null, "%", "%");
        dbmeta.getImportedKeys("PUBLIC", "PUBLIC", "T_1");
        dbmeta.getIndexInfo("PUBLIC", "PUBLIC", "T1", true, true);
        dbmeta.getPrimaryKeys("PUBLIC", "PUBLIC", "T_1");
        dbmeta.getProcedureColumns(null, null, "%", "%");
        dbmeta.getProcedures("PUBLIC", "%", "%");
        dbmeta.getSchemas(null, "#");
        dbmeta.getTablePrivileges(null, "%", "%");
        dbmeta.getUDTs(null, "%", "%", new int[]{ Types.DISTINCT });
    } catch (Exception e) {
        assertTrue("unable to prepare or execute DDL", false);
    } finally {
        conn.close();
    }
}
 
Example 6
Source File: MetaResultSetTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@Test public void testGetFunctions() throws SQLException {
  DatabaseMetaData metadata = getDatabaseMetadata();
  try (ResultSet rs = metadata.getFunctions(null, null, null)) {
    ResultSetMetaData rsMeta = rs.getMetaData();

    assertEquals(6, rsMeta.getColumnCount());
    assertColumn(rsMeta, 1, "FUNCTION_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
    assertColumn(rsMeta, 2, "FUNCTION_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
    assertColumn(rsMeta, 3, "FUNCTION_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
    assertColumn(rsMeta, 4, "REMARKS", Types.VARCHAR, DatabaseMetaData.columnNullable);
    assertColumn(rsMeta, 5, "FUNCTION_TYPE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
    assertColumn(rsMeta, 6, "SPECIFIC_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
  }
}
 
Example 7
Source File: MetaDataRegressionTest.java    From r-course with MIT License 4 votes vote down vote up
private void checkMetaDataInfoForBug17248345(Connection testConn) throws Exception {
    DatabaseMetaData testDbMetaData = testConn.getMetaData();
    ResultSet rsMD;
    boolean useInfoSchema = ((ConnectionProperties) testConn).getUseInformationSchema();
    boolean getProcRetFunc = ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions();
    String stepDescription = "Prop. useInfoSchema(" + (useInfoSchema ? 1 : 0) + ") + getProcRetFunc(" + (getProcRetFunc ? 1 : 0) + "):";
    String sd;

    // getFunctions() must return 1 record.
    sd = stepDescription + " getFunctions() ";
    rsMD = testDbMetaData.getFunctions(null, null, "testBug17248345");
    assertTrue(sd + "one row expected.", rsMD.next());
    assertEquals(sd + " -> FUNCTION_NAME", "testBug17248345", rsMD.getString("FUNCTION_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());

    // getFunctionColumns() must return 2 records (func return + func param).
    sd = stepDescription + " getFunctionColumns() ";
    rsMD = testDbMetaData.getFunctionColumns(null, null, "testBug17248345", "%");
    assertTrue(sd + "1st of 2 rows expected.", rsMD.next());
    assertEquals(sd + " -> FUNCTION_NAME", "testBug17248345", rsMD.getString("FUNCTION_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "", rsMD.getString("COLUMN_NAME"));
    assertTrue(sd + "2nd of 2 rows expected.", rsMD.next());
    assertEquals(sd + " -> FUNCTION_NAME", "testBug17248345", rsMD.getString("FUNCTION_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "funccol", rsMD.getString("COLUMN_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());

    // getProcedures() must return 1 or 2 records, depending on if getProceduresReturnsFunctions is false or true
    // respectively. When exists a procedure and a function with same name, function is returned first.
    sd = stepDescription + " getProcedures() ";
    rsMD = testDbMetaData.getProcedures(null, null, "testBug17248345");
    if (getProcRetFunc) {
        assertTrue(sd + "1st of 2 rows expected.", rsMD.next());
        assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
        assertTrue(sd + "2nd of 2 rows expected.", rsMD.next());
    } else {
        assertTrue(sd + "one row expected.", rsMD.next());
    }
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());

    // getProcedureColumns() must return 1 or 3 records, depending on if getProceduresReturnsFunctions is false or
    // true respectively. When exists a procedure and a function with same name, function is returned first.
    sd = stepDescription + " getProcedureColumns() ";
    rsMD = testDbMetaData.getProcedureColumns(null, null, "testBug17248345", "%");
    if (getProcRetFunc) {
        assertTrue(sd + "1st of 3 rows expected.", rsMD.next());
        assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
        assertEquals(sd + " -> COLUMN_NAME", "", rsMD.getString("COLUMN_NAME"));
        assertTrue(sd + "2nd of 3 rows expected.", rsMD.next());
        assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
        assertEquals(sd + " -> COLUMN_NAME", "funccol", rsMD.getString("COLUMN_NAME"));
        assertTrue(sd + "3rd of 3 rows expected.", rsMD.next());
    } else {
        assertTrue(sd + "one row expected.", rsMD.next());
    }
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "proccol", rsMD.getString("COLUMN_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());
}
 
Example 8
Source File: MetaDataRegressionTest.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
private void checkMetaDataInfoForBug17248345(Connection testConn) throws Exception {
    DatabaseMetaData testDbMetaData = testConn.getMetaData();
    ResultSet rsMD;
    boolean useInfoSchema = ((ConnectionProperties) testConn).getUseInformationSchema();
    boolean getProcRetFunc = ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions();
    String stepDescription = "Prop. useInfoSchema(" + (useInfoSchema ? 1 : 0) + ") + getProcRetFunc(" + (getProcRetFunc ? 1 : 0) + "):";
    String sd;

    // getFunctions() must return 1 record.
    sd = stepDescription + " getFunctions() ";
    rsMD = testDbMetaData.getFunctions(null, null, "testBug17248345");
    assertTrue(sd + "one row expected.", rsMD.next());
    assertEquals(sd + " -> FUNCTION_NAME", "testBug17248345", rsMD.getString("FUNCTION_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());

    // getFunctionColumns() must return 2 records (func return + func param).
    sd = stepDescription + " getFunctionColumns() ";
    rsMD = testDbMetaData.getFunctionColumns(null, null, "testBug17248345", "%");
    assertTrue(sd + "1st of 2 rows expected.", rsMD.next());
    assertEquals(sd + " -> FUNCTION_NAME", "testBug17248345", rsMD.getString("FUNCTION_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "", rsMD.getString("COLUMN_NAME"));
    assertTrue(sd + "2nd of 2 rows expected.", rsMD.next());
    assertEquals(sd + " -> FUNCTION_NAME", "testBug17248345", rsMD.getString("FUNCTION_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "funccol", rsMD.getString("COLUMN_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());

    // getProcedures() must return 1 or 2 records, depending on if getProceduresReturnsFunctions is false or true
    // respectively. When exists a procedure and a function with same name, function is returned first.
    sd = stepDescription + " getProcedures() ";
    rsMD = testDbMetaData.getProcedures(null, null, "testBug17248345");
    if (getProcRetFunc) {
        assertTrue(sd + "1st of 2 rows expected.", rsMD.next());
        assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
        assertTrue(sd + "2nd of 2 rows expected.", rsMD.next());
    } else {
        assertTrue(sd + "one row expected.", rsMD.next());
    }
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());

    // getProcedureColumns() must return 1 or 3 records, depending on if getProceduresReturnsFunctions is false or
    // true respectively. When exists a procedure and a function with same name, function is returned first.
    sd = stepDescription + " getProcedureColumns() ";
    rsMD = testDbMetaData.getProcedureColumns(null, null, "testBug17248345", "%");
    if (getProcRetFunc) {
        assertTrue(sd + "1st of 3 rows expected.", rsMD.next());
        assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
        assertEquals(sd + " -> COLUMN_NAME", "", rsMD.getString("COLUMN_NAME"));
        assertTrue(sd + "2nd of 3 rows expected.", rsMD.next());
        assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
        assertEquals(sd + " -> COLUMN_NAME", "funccol", rsMD.getString("COLUMN_NAME"));
        assertTrue(sd + "3rd of 3 rows expected.", rsMD.next());
    } else {
        assertTrue(sd + "one row expected.", rsMD.next());
    }
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "proccol", rsMD.getString("COLUMN_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());
}