Java Code Examples for java.sql.DatabaseMetaData#getFunctionColumns()
The following examples show how to use
java.sql.DatabaseMetaData#getFunctionColumns() .
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: SQLQuery.java From micro-integrator with Apache License 2.0 | 6 votes |
private Object[] getStoredProcFuncProps(String name) throws DataServiceFault, SQLException { Connection conn = (Connection) this.getConfig().createConnection()[0]; DatabaseMetaData md = conn.getMetaData(); ResultSet rs = null; boolean error = true; try { rs = md.getProcedureColumns(null, null, name, "%"); Object[] resultMap = new Object[2]; if (!rs.next()) { rs.close(); rs = md.getFunctionColumns(null, null, name, "%"); } else { rs.close(); rs = md.getProcedureColumns(null, null, name, "%"); } resultMap[0] = conn; resultMap[1] = rs; error = false; return resultMap; } finally { if (error) { this.releaseResources(rs, null); } } }
Example 2
Source File: MetaDataRegressionTest.java From r-course with MIT License | 6 votes |
private void checkFunctionColumnTypeForBug68307(String testAgainst, DatabaseMetaData testDbMetaData) throws Exception { rs = testDbMetaData.getFunctionColumns(null, null, "testBug68307_%", "%"); while (rs.next()) { String message = testAgainst + ", function <" + rs.getString("FUNCTION_NAME") + "." + rs.getString("COLUMN_NAME") + ">"; if (rs.getString("COLUMN_NAME") == null || rs.getString("COLUMN_NAME").length() == 0) { assertEquals(message, DatabaseMetaData.functionReturn, rs.getShort("COLUMN_TYPE")); } else if (rs.getString("COLUMN_NAME").endsWith("_in")) { assertEquals(message, DatabaseMetaData.functionColumnIn, rs.getShort("COLUMN_TYPE")); } else if (rs.getString("COLUMN_NAME").endsWith("_inout")) { assertEquals(message, DatabaseMetaData.functionColumnInOut, rs.getShort("COLUMN_TYPE")); } else if (rs.getString("COLUMN_NAME").endsWith("_out")) { assertEquals(message, DatabaseMetaData.functionColumnOut, rs.getShort("COLUMN_TYPE")); } else { fail("Column '" + rs.getString("FUNCTION_NAME") + "." + rs.getString("COLUMN_NAME") + "' not expected within test case."); } } }
Example 3
Source File: MetaResultSetTest.java From calcite-avatica with Apache License 2.0 | 6 votes |
@Test public void testGetFunctionColumns() throws SQLException { DatabaseMetaData metadata = getDatabaseMetadata(); try (ResultSet rs = metadata.getFunctionColumns(null, null, null, null)) { ResultSetMetaData rsMeta = rs.getMetaData(); assertEquals(17, 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, "COLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 5, "COLUMN_TYPE", Types.SMALLINT, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 6, "DATA_TYPE", Types.INTEGER, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 7, "TYPE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 8, "PRECISION", Types.INTEGER, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 9, "LENGTH", Types.INTEGER, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 10, "SCALE", Types.SMALLINT, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 11, "RADIX", Types.SMALLINT, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 12, "NULLABLE", Types.SMALLINT, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 13, "REMARKS", Types.VARCHAR, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 14, "CHAR_OCTET_LENGTH", Types.INTEGER, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 15, "ORDINAL_POSITION", Types.INTEGER, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 16, "IS_NULLABLE", Types.VARCHAR, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 17, "SPECIFIC_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable); } }
Example 4
Source File: MetaDataRegressionTest.java From Komondor with GNU General Public License v3.0 | 6 votes |
private void checkFunctionColumnTypeForBug68307(String testAgainst, DatabaseMetaData testDbMetaData) throws Exception { rs = testDbMetaData.getFunctionColumns(null, null, "testBug68307_%", "%"); while (rs.next()) { String message = testAgainst + ", function <" + rs.getString("FUNCTION_NAME") + "." + rs.getString("COLUMN_NAME") + ">"; if (rs.getString("COLUMN_NAME") == null || rs.getString("COLUMN_NAME").length() == 0) { assertEquals(message, DatabaseMetaData.functionReturn, rs.getShort("COLUMN_TYPE")); } else if (rs.getString("COLUMN_NAME").endsWith("_in")) { assertEquals(message, DatabaseMetaData.functionColumnIn, rs.getShort("COLUMN_TYPE")); } else if (rs.getString("COLUMN_NAME").endsWith("_inout")) { assertEquals(message, DatabaseMetaData.functionColumnInOut, rs.getShort("COLUMN_TYPE")); } else if (rs.getString("COLUMN_NAME").endsWith("_out")) { assertEquals(message, DatabaseMetaData.functionColumnOut, rs.getShort("COLUMN_TYPE")); } else { fail("Column '" + rs.getString("FUNCTION_NAME") + "." + rs.getString("COLUMN_NAME") + "' not expected within test case."); } } }
Example 5
Source File: TestDatabaseMetaData.java From evosql with Apache License 2.0 | 5 votes |
/** * 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: Show.java From jsqsh with Apache License 2.0 | 5 votes |
private ResultSet doFunction(Session session, Connection con, Options options) throws SQLException { if (options.arguments.size() < 2 || options.arguments.size() > 3 || !options.arguments.get(1).equalsIgnoreCase("params")) { session.err.println("Use: \\show function params [-p param-pattern] [[[catalog.]schema-pattern.]func-pattern]"); return null; } if (options.essential) { options.columns = essentialFunctionParamsCols; } SQLConnectionContext ctx = (SQLConnectionContext) session.getConnectionContext(); SQLObjectName name = (options.arguments.size() == 3) ? new SQLObjectName(ctx, options.arguments.get(2)) : new SQLObjectName(ctx, "%"); DatabaseMetaData meta = con.getMetaData(); return meta.getFunctionColumns( (options.catalog != null ? options.catalog : name.getCatalog()), (options.schemaPattern != null ? options.schemaPattern : name.getSchema()), (options.tablePattern != null ? options.tablePattern : name.getName()), ctx.normalizeIdentifier(options.pattern)); }
Example 7
Source File: MetaDataRegressionTest.java From r-course with MIT License | 4 votes |
private void checkGetFunctionColumnsForBug69298(String stepDescription, Connection testConn) throws Exception { DatabaseMetaData testDbMetaData = testConn.getMetaData(); ResultSet funcColsMD = testDbMetaData.getFunctionColumns(null, null, "testBug69298_%", "%"); String sd = stepDescription + " getFunctionColumns() "; assertTrue(sd + "1st of 2 rows expected.", funcColsMD.next()); // function column: testBug69298_func return assertEquals(sd + "-> FUNCTION_CAT", testConn.getCatalog(), funcColsMD.getString("FUNCTION_CAT")); assertEquals(sd + "-> FUNCTION_SCHEM", null, funcColsMD.getString("FUNCTION_SCHEM")); assertEquals(sd + "-> FUNCTION_NAME", "testBug69298_func", funcColsMD.getString("FUNCTION_NAME")); assertEquals(sd + "-> COLUMN_NAME", "", funcColsMD.getString("COLUMN_NAME")); assertEquals(sd + "-> COLUMN_TYPE", DatabaseMetaData.functionReturn, funcColsMD.getShort("COLUMN_TYPE")); assertEquals(sd + "-> DATA_TYPE", Types.INTEGER, funcColsMD.getInt("DATA_TYPE")); assertEquals(sd + "-> TYPE_NAME", "INT", funcColsMD.getString("TYPE_NAME")); assertEquals(sd + "-> PRECISION", 10, funcColsMD.getInt("PRECISION")); assertEquals(sd + "-> LENGTH", 10, funcColsMD.getInt("LENGTH")); assertEquals(sd + "-> SCALE", 0, funcColsMD.getShort("SCALE")); assertEquals(sd + "-> RADIX", 10, funcColsMD.getShort("RADIX")); assertEquals(sd + "-> NULLABLE", DatabaseMetaData.functionNullable, funcColsMD.getShort("NULLABLE")); assertEquals(sd + "-> REMARKS", null, funcColsMD.getString("REMARKS")); assertEquals(sd + "-> CHAR_OCTET_LENGTH", 0, funcColsMD.getInt("CHAR_OCTET_LENGTH")); assertEquals(sd + "-> ORDINAL_POSITION", 0, funcColsMD.getInt("ORDINAL_POSITION")); assertEquals(sd + "-> IS_NULLABLE", "YES", funcColsMD.getString("IS_NULLABLE")); assertEquals(sd + "-> SPECIFIC_NAME", "testBug69298_func", funcColsMD.getString("SPECIFIC_NAME")); assertTrue(sd + "2nd of 2 rows expected.", funcColsMD.next()); // function column: testBug69298_func.param_func assertEquals(sd + "-> FUNCTION_CAT", testConn.getCatalog(), funcColsMD.getString("FUNCTION_CAT")); assertEquals(sd + "-> FUNCTION_SCHEM", null, funcColsMD.getString("FUNCTION_SCHEM")); assertEquals(sd + "-> FUNCTION_NAME", "testBug69298_func", funcColsMD.getString("FUNCTION_NAME")); assertEquals(sd + "-> COLUMN_NAME", "param_func", funcColsMD.getString("COLUMN_NAME")); assertEquals(sd + "-> COLUMN_TYPE", DatabaseMetaData.functionColumnIn, funcColsMD.getShort("COLUMN_TYPE")); assertEquals(sd + "-> DATA_TYPE", Types.INTEGER, funcColsMD.getInt("DATA_TYPE")); assertEquals(sd + "-> TYPE_NAME", "INT", funcColsMD.getString("TYPE_NAME")); assertEquals(sd + "-> PRECISION", 10, funcColsMD.getInt("PRECISION")); assertEquals(sd + "-> LENGTH", 10, funcColsMD.getInt("LENGTH")); assertEquals(sd + "-> SCALE", 0, funcColsMD.getShort("SCALE")); assertEquals(sd + "-> RADIX", 10, funcColsMD.getShort("RADIX")); assertEquals(sd + "-> NULLABLE", DatabaseMetaData.functionNullable, funcColsMD.getShort("NULLABLE")); assertEquals(sd + "-> REMARKS", null, funcColsMD.getString("REMARKS")); assertEquals(sd + "-> CHAR_OCTET_LENGTH", 0, funcColsMD.getInt("CHAR_OCTET_LENGTH")); assertEquals(sd + "-> ORDINAL_POSITION", 1, funcColsMD.getInt("ORDINAL_POSITION")); assertEquals(sd + "-> IS_NULLABLE", "YES", funcColsMD.getString("IS_NULLABLE")); assertEquals(sd + "-> SPECIFIC_NAME", "testBug69298_func", funcColsMD.getString("SPECIFIC_NAME")); assertFalse(sd + "no more rows expected.", funcColsMD.next()); }
Example 8
Source File: MetaDataRegressionTest.java From r-course with MIT License | 4 votes |
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 9
Source File: MetaDataRegressionTest.java From r-course with MIT License | 4 votes |
/** * Tests fix for BUG#20727196 - GETPROCEDURECOLUMNS() RETURNS EXCEPTION FOR FUNCTION WHICH RETURNS ENUM/SET TYPE. * * Test duplicated in testsuite.regression.MetaDataRegressionTest. * * @throws Exception * if the test fails. */ public void testBug20727196() throws Exception { createFunction("testBug20727196_f1", "(p ENUM ('Yes', 'No')) RETURNS VARCHAR(10) DETERMINISTIC BEGIN RETURN IF(p='Yes', 'Yay!', if(p='No', 'Ney!', 'What?')); END"); createFunction("testBug20727196_f2", "(p CHAR(1)) RETURNS ENUM ('Yes', 'No') DETERMINISTIC BEGIN RETURN IF(p='y', 'Yes', if(p='n', 'No', '?')); END"); createFunction("testBug20727196_f3", "(p ENUM ('Yes', 'No')) RETURNS ENUM ('Yes', 'No') DETERMINISTIC BEGIN RETURN IF(p='Yes', 'Yes', if(p='No', 'No', '?')); END"); createProcedure("testBug20727196_p1", "(p ENUM ('Yes', 'No')) BEGIN SELECT IF(p='Yes', 'Yay!', if(p='No', 'Ney!', 'What?')); END"); for (String connProps : new String[] { "getProceduresReturnsFunctions=false,useInformationSchema=false", "getProceduresReturnsFunctions=false,useInformationSchema=true" }) { Connection testConn = null; try { testConn = getConnectionWithProps(connProps); DatabaseMetaData dbmd = testConn.getMetaData(); this.rs = dbmd.getFunctionColumns(null, null, "testBug20727196_%", "%"); // testBug20727196_f1 columns: assertTrue(this.rs.next()); assertEquals("testBug20727196_f1", this.rs.getString(3)); assertEquals("", this.rs.getString(4)); assertEquals("VARCHAR", this.rs.getString(7)); assertTrue(this.rs.next()); assertEquals("testBug20727196_f1", this.rs.getString(3)); assertEquals("p", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); // testBug20727196_f2 columns: assertTrue(this.rs.next()); assertEquals("testBug20727196_f2", this.rs.getString(3)); assertEquals("", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); assertTrue(this.rs.next()); assertEquals("testBug20727196_f2", this.rs.getString(3)); assertEquals("p", this.rs.getString(4)); assertEquals("CHAR", this.rs.getString(7)); // testBug20727196_f3 columns: assertTrue(this.rs.next()); assertEquals("testBug20727196_f3", this.rs.getString(3)); assertEquals("", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); assertTrue(this.rs.next()); assertEquals("testBug20727196_f3", this.rs.getString(3)); assertEquals("p", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); assertFalse(this.rs.next()); this.rs = dbmd.getProcedureColumns(null, null, "testBug20727196_%", "%"); // testBug20727196_p1 columns: assertTrue(this.rs.next()); assertEquals("testBug20727196_p1", this.rs.getString(3)); assertEquals("p", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); assertFalse(this.rs.next()); } finally { if (testConn != null) { testConn.close(); } } } }
Example 10
Source File: MetaDataRegressionTest.java From Komondor with GNU General Public License v3.0 | 4 votes |
private void checkGetFunctionColumnsForBug69298(String stepDescription, Connection testConn) throws Exception { DatabaseMetaData testDbMetaData = testConn.getMetaData(); ResultSet funcColsMD = testDbMetaData.getFunctionColumns(null, null, "testBug69298_%", "%"); String sd = stepDescription + " getFunctionColumns() "; assertTrue(sd + "1st of 2 rows expected.", funcColsMD.next()); // function column: testBug69298_func return assertEquals(sd + "-> FUNCTION_CAT", testConn.getCatalog(), funcColsMD.getString("FUNCTION_CAT")); assertEquals(sd + "-> FUNCTION_SCHEM", null, funcColsMD.getString("FUNCTION_SCHEM")); assertEquals(sd + "-> FUNCTION_NAME", "testBug69298_func", funcColsMD.getString("FUNCTION_NAME")); assertEquals(sd + "-> COLUMN_NAME", "", funcColsMD.getString("COLUMN_NAME")); assertEquals(sd + "-> COLUMN_TYPE", DatabaseMetaData.functionReturn, funcColsMD.getShort("COLUMN_TYPE")); assertEquals(sd + "-> DATA_TYPE", Types.INTEGER, funcColsMD.getInt("DATA_TYPE")); assertEquals(sd + "-> TYPE_NAME", "INT", funcColsMD.getString("TYPE_NAME")); assertEquals(sd + "-> PRECISION", 10, funcColsMD.getInt("PRECISION")); assertEquals(sd + "-> LENGTH", 10, funcColsMD.getInt("LENGTH")); assertEquals(sd + "-> SCALE", 0, funcColsMD.getShort("SCALE")); assertEquals(sd + "-> RADIX", 10, funcColsMD.getShort("RADIX")); assertEquals(sd + "-> NULLABLE", DatabaseMetaData.functionNullable, funcColsMD.getShort("NULLABLE")); assertEquals(sd + "-> REMARKS", null, funcColsMD.getString("REMARKS")); assertEquals(sd + "-> CHAR_OCTET_LENGTH", 0, funcColsMD.getInt("CHAR_OCTET_LENGTH")); assertEquals(sd + "-> ORDINAL_POSITION", 0, funcColsMD.getInt("ORDINAL_POSITION")); assertEquals(sd + "-> IS_NULLABLE", "YES", funcColsMD.getString("IS_NULLABLE")); assertEquals(sd + "-> SPECIFIC_NAME", "testBug69298_func", funcColsMD.getString("SPECIFIC_NAME")); assertTrue(sd + "2nd of 2 rows expected.", funcColsMD.next()); // function column: testBug69298_func.param_func assertEquals(sd + "-> FUNCTION_CAT", testConn.getCatalog(), funcColsMD.getString("FUNCTION_CAT")); assertEquals(sd + "-> FUNCTION_SCHEM", null, funcColsMD.getString("FUNCTION_SCHEM")); assertEquals(sd + "-> FUNCTION_NAME", "testBug69298_func", funcColsMD.getString("FUNCTION_NAME")); assertEquals(sd + "-> COLUMN_NAME", "param_func", funcColsMD.getString("COLUMN_NAME")); assertEquals(sd + "-> COLUMN_TYPE", DatabaseMetaData.functionColumnIn, funcColsMD.getShort("COLUMN_TYPE")); assertEquals(sd + "-> DATA_TYPE", Types.INTEGER, funcColsMD.getInt("DATA_TYPE")); assertEquals(sd + "-> TYPE_NAME", "INT", funcColsMD.getString("TYPE_NAME")); assertEquals(sd + "-> PRECISION", 10, funcColsMD.getInt("PRECISION")); assertEquals(sd + "-> LENGTH", 10, funcColsMD.getInt("LENGTH")); assertEquals(sd + "-> SCALE", 0, funcColsMD.getShort("SCALE")); assertEquals(sd + "-> RADIX", 10, funcColsMD.getShort("RADIX")); assertEquals(sd + "-> NULLABLE", DatabaseMetaData.functionNullable, funcColsMD.getShort("NULLABLE")); assertEquals(sd + "-> REMARKS", null, funcColsMD.getString("REMARKS")); assertEquals(sd + "-> CHAR_OCTET_LENGTH", 0, funcColsMD.getInt("CHAR_OCTET_LENGTH")); assertEquals(sd + "-> ORDINAL_POSITION", 1, funcColsMD.getInt("ORDINAL_POSITION")); assertEquals(sd + "-> IS_NULLABLE", "YES", funcColsMD.getString("IS_NULLABLE")); assertEquals(sd + "-> SPECIFIC_NAME", "testBug69298_func", funcColsMD.getString("SPECIFIC_NAME")); assertFalse(sd + "no more rows expected.", funcColsMD.next()); }
Example 11
Source File: MetaDataRegressionTest.java From Komondor with GNU General Public License v3.0 | 4 votes |
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 12
Source File: MetaDataRegressionTest.java From Komondor with GNU General Public License v3.0 | 4 votes |
/** * Tests fix for BUG#20727196 - GETPROCEDURECOLUMNS() RETURNS EXCEPTION FOR FUNCTION WHICH RETURNS ENUM/SET TYPE. * * Test duplicated in testsuite.regression.MetaDataRegressionTest. * * @throws Exception * if the test fails. */ public void testBug20727196() throws Exception { createFunction("testBug20727196_f1", "(p ENUM ('Yes', 'No')) RETURNS VARCHAR(10) DETERMINISTIC BEGIN RETURN IF(p='Yes', 'Yay!', if(p='No', 'Ney!', 'What?')); END"); createFunction("testBug20727196_f2", "(p CHAR(1)) RETURNS ENUM ('Yes', 'No') DETERMINISTIC BEGIN RETURN IF(p='y', 'Yes', if(p='n', 'No', '?')); END"); createFunction("testBug20727196_f3", "(p ENUM ('Yes', 'No')) RETURNS ENUM ('Yes', 'No') DETERMINISTIC BEGIN RETURN IF(p='Yes', 'Yes', if(p='No', 'No', '?')); END"); createProcedure("testBug20727196_p1", "(p ENUM ('Yes', 'No')) BEGIN SELECT IF(p='Yes', 'Yay!', if(p='No', 'Ney!', 'What?')); END"); for (String connProps : new String[] { "getProceduresReturnsFunctions=false,useInformationSchema=false", "getProceduresReturnsFunctions=false,useInformationSchema=true" }) { Connection testConn = null; try { testConn = getConnectionWithProps(connProps); DatabaseMetaData dbmd = testConn.getMetaData(); this.rs = dbmd.getFunctionColumns(null, null, "testBug20727196_%", "%"); // testBug20727196_f1 columns: assertTrue(this.rs.next()); assertEquals("testBug20727196_f1", this.rs.getString(3)); assertEquals("", this.rs.getString(4)); assertEquals("VARCHAR", this.rs.getString(7)); assertTrue(this.rs.next()); assertEquals("testBug20727196_f1", this.rs.getString(3)); assertEquals("p", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); // testBug20727196_f2 columns: assertTrue(this.rs.next()); assertEquals("testBug20727196_f2", this.rs.getString(3)); assertEquals("", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); assertTrue(this.rs.next()); assertEquals("testBug20727196_f2", this.rs.getString(3)); assertEquals("p", this.rs.getString(4)); assertEquals("CHAR", this.rs.getString(7)); // testBug20727196_f3 columns: assertTrue(this.rs.next()); assertEquals("testBug20727196_f3", this.rs.getString(3)); assertEquals("", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); assertTrue(this.rs.next()); assertEquals("testBug20727196_f3", this.rs.getString(3)); assertEquals("p", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); assertFalse(this.rs.next()); this.rs = dbmd.getProcedureColumns(null, null, "testBug20727196_%", "%"); // testBug20727196_p1 columns: assertTrue(this.rs.next()); assertEquals("testBug20727196_p1", this.rs.getString(3)); assertEquals("p", this.rs.getString(4)); assertEquals("ENUM", this.rs.getString(7)); assertFalse(this.rs.next()); } finally { if (testConn != null) { testConn.close(); } } } }