java.sql.ParameterMetaData Java Examples

The following examples show how to use java.sql.ParameterMetaData. 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: PhoenixPreparedStatement.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
    int paramCount = statement.getBindCount();
    List<Object> params = this.getParameters();
    BitSet unsetParams = new BitSet(statement.getBindCount());
    for (int i = 0; i < paramCount; i++) {
        if ( params.get(i) == BindManager.UNBOUND_PARAMETER) {
            unsetParams.set(i);
            params.set(i, null);
        }
    }
    try {
        StatementPlan plan = statement.compilePlan(this, Sequence.ValueOp.VALIDATE_SEQUENCE);
        return plan.getParameterMetaData();
    } finally {
        int lastSetBit = 0;
        while ((lastSetBit = unsetParams.nextSetBit(lastSetBit)) != -1) {
            params.set(lastSetBit, BindManager.UNBOUND_PARAMETER);
            lastSetBit++;
        }
    }
}
 
Example #2
Source File: ParameterMetaDataJdbc30Test.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
        * tests parameterMetaData and reports error if the ParameterMetaData results
 * does not match the expected results.
        *
        * @param paramMetaData ParameterMetadata object
 * @param paramMetaDataArray 2 dimensional array containing expected test results. 
 * @exception SQLException if any error occurs
        */
static void testParameterMetaData(ParameterMetaData paramMetaData, String [][] paramMetaDataArray) throws SQLException {
	int numParam = paramMetaData.getParameterCount();
	
	for (int i=0, j=0; i<numParam; i++) {	
                      	assertEquals("Unexpected parameter isNullable", paramMetaDataArray[i][j++], parameterIsNullableInStringForm(paramMetaData.isNullable(i+1)));
                      	assertEquals("Unexpected parameter isSigned", Boolean.valueOf(paramMetaDataArray[i][j++]).booleanValue(), paramMetaData.isSigned(i+1));
                      	assertEquals("Unexpected parameter getPrecision", Integer.parseInt(paramMetaDataArray[i][j++]) ,  paramMetaData.getPrecision(i+1));
                      	assertEquals("Unexpected parameter getScale", Integer.parseInt(paramMetaDataArray[i][j++]) , paramMetaData.getScale(i+1));
                      	assertEquals("Unexpected parameter getParameterType", Integer.parseInt(paramMetaDataArray[i][j++]) , paramMetaData.getParameterType(i+1));
                      	assertEquals("Unexpected parameter getParameterTypeName", paramMetaDataArray[i][j++] , paramMetaData.getParameterTypeName(i+1));
                      	assertEquals("Unexpected parameter getParameterClassName", paramMetaDataArray[i][j++] , paramMetaData.getParameterClassName(i+1));
                      	assertEquals("Unexpected parameter getParameterMode", paramMetaDataArray[i][j++] , parameterModeInStringForm(paramMetaData.getParameterMode(i+1)));
		
		j=0;
	}
}
 
Example #3
Source File: UDTTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Check the ParameterMetaData for a statement whose first parameter is a UDT.
 */
private void checkPMD
    (
     Connection conn,
     String query,
     String expectedClassName,
     int expectedJDBCType,
     String expectedSQLTypeName,
     int expectedPrecision,
     int expectedScale
     ) throws Exception
{
    PreparedStatement ps = conn.prepareStatement( query );
    ParameterMetaData pmd = ps.getParameterMetaData();

    assertEquals( pmd.getParameterClassName( 1 ), expectedClassName );
    assertEquals( pmd.getParameterType( 1 ), expectedJDBCType );
    assertEquals( pmd.getParameterTypeName( 1 ), expectedSQLTypeName );
    assertEquals( pmd.getPrecision( 1 ), expectedPrecision );
    assertEquals( pmd.getScale( 1 ), expectedScale );

    ps.close();
}
 
Example #4
Source File: UnionPlan.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public UnionPlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector,
        Integer limit, Integer offset, OrderBy orderBy, GroupBy groupBy, List<QueryPlan> plans, ParameterMetaData paramMetaData) throws SQLException {
    this.parentContext = context;
    this.statement = statement;
    this.tableRef = table;
    this.projector = projector;
    this.limit = limit;
    this.orderBy = orderBy;
    this.groupBy = groupBy;
    this.plans = plans;
    this.offset= offset;
    this.paramMetaData = paramMetaData;
    boolean isDegen = true;
    for (QueryPlan plan : plans) {           
        if (plan.getContext().getScanRanges() != ScanRanges.NOTHING) {
            isDegen = false;
            break;
        }
    }
    this.isDegenerate = isDegen;     
}
 
Example #5
Source File: QueryWithOffsetIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testMetaDataWithOffset() throws SQLException {
    Connection conn;
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    conn = DriverManager.getConnection(getUrl(), props);
    createTestTable(getUrl(), ddl);
    initTableValues(conn);
    updateStatistics(conn);
    PreparedStatement stmt = conn.prepareStatement("SELECT * from " + tableName + " offset ?");
    ParameterMetaData pmd = stmt.getParameterMetaData();
    assertEquals(1, pmd.getParameterCount());
    assertEquals(Types.INTEGER, pmd.getParameterType(1));
    stmt.setInt(1, 10);
    ResultSet rs = stmt.executeQuery();
    ResultSetMetaData md = rs.getMetaData();
    assertEquals(5, md.getColumnCount());
}
 
Example #6
Source File: ParameterMetaDataJdbc30Test.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
        * tests parameterMetaData and reports error if the ParameterMetaData results
 * does not match the expected results.
        *
        * @param paramMetaData ParameterMetadata object
 * @param paramMetaDataArray 2 dimensional array containing expected test results. 
 * @exception SQLException if any error occurs
        */
static void testParameterMetaData(ParameterMetaData paramMetaData, String [][] paramMetaDataArray) throws SQLException {
	int numParam = paramMetaData.getParameterCount();
	
	for (int i=0, j=0; i<numParam; i++) {	
                      	assertEquals("Unexpected parameter isNullable", paramMetaDataArray[i][j++], parameterIsNullableInStringForm(paramMetaData.isNullable(i+1)));
                      	assertEquals("Unexpected parameter isSigned", Boolean.valueOf(paramMetaDataArray[i][j++]).booleanValue(), paramMetaData.isSigned(i+1));
                      	assertEquals("Unexpected parameter getPrecision", Integer.parseInt(paramMetaDataArray[i][j++]) ,  paramMetaData.getPrecision(i+1));
                      	assertEquals("Unexpected parameter getScale", Integer.parseInt(paramMetaDataArray[i][j++]) , paramMetaData.getScale(i+1));
                      	assertEquals("Unexpected parameter getParameterType", Integer.parseInt(paramMetaDataArray[i][j++]) , paramMetaData.getParameterType(i+1));
                      	assertEquals("Unexpected parameter getParameterTypeName", paramMetaDataArray[i][j++] , paramMetaData.getParameterTypeName(i+1));
                      	assertEquals("Unexpected parameter getParameterClassName", paramMetaDataArray[i][j++] , paramMetaData.getParameterClassName(i+1));
                      	assertEquals("Unexpected parameter getParameterMode", paramMetaDataArray[i][j++] , parameterModeInStringForm(paramMetaData.getParameterMode(i+1)));
		
		j=0;
	}
}
 
Example #7
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testCaseMetaData() throws Exception {
    String query1 = "SELECT a_string, b_string FROM atable WHERE case when a_integer = 1 then ? when a_integer > 2 then 2 end > 3";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query1);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(1, pmd.getParameterCount());
    assertEquals(BigDecimal.class.getName(), pmd.getParameterClassName(1));
    assertEquals(ParameterMetaData.parameterNullable, pmd.isNullable(1));
    
    String query2 = "SELECT a_string, b_string FROM atable WHERE case when a_integer = 1 then 1 when a_integer > 2 then 2 end > ?";
    PreparedStatement statement2 = conn.prepareStatement(query2);
    ParameterMetaData pmd2 = statement2.getParameterMetaData();
    assertEquals(1, pmd2.getParameterCount());
    assertEquals(Integer.class.getName(), pmd2.getParameterClassName(1));
    assertEquals(ParameterMetaData.parameterNullable, pmd2.isNullable(1));
}
 
Example #8
Source File: PreparedStatement2IT.java    From snowflake-jdbc with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrepareAndGetMeta() throws SQLException
{
  try (Connection con = init())
  {
    try (PreparedStatement prepStatement = con.prepareStatement("select 1 where 1 > ?"))
    {
      ResultSetMetaData meta = prepStatement.getMetaData();
      assertThat(meta.getColumnCount(), is(1));
    }
    try (PreparedStatement prepStatement = con.prepareStatement("select 1 where 1 > ?"))
    {
      ParameterMetaData parameterMetaData = prepStatement.getParameterMetaData();
      assertThat(parameterMetaData.getParameterCount(), is(1));
    }
  }
}
 
Example #9
Source File: UDTTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Check the ParameterMetaData for a statement whose first parameter is a UDT.
 */
private void checkPMD
    (
     Connection conn,
     String query,
     String expectedClassName,
     int expectedJDBCType,
     String expectedSQLTypeName,
     int expectedPrecision,
     int expectedScale
     ) throws Exception
{
    PreparedStatement ps = conn.prepareStatement( query );
    ParameterMetaData pmd = ps.getParameterMetaData();

    assertEquals( pmd.getParameterClassName( 1 ), expectedClassName );
    assertEquals( pmd.getParameterType( 1 ), expectedJDBCType );
    assertEquals( pmd.getParameterTypeName( 1 ), expectedSQLTypeName );
    assertEquals( pmd.getPrecision( 1 ), expectedPrecision );
    assertEquals( pmd.getScale( 1 ), expectedScale );

    ps.close();
}
 
Example #10
Source File: SnowflakeParameterMetadata.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public int isNullable(int param) throws SQLException
{
  MetaDataOfBinds paramInfo = statementMetaData.getMetaDataForBindParam(param);
  if (paramInfo.isNullable())
  {
    return ParameterMetaData.parameterNullable;
  }
  return ParameterMetaData.parameterNoNulls;
}
 
Example #11
Source File: ClientPreparedStatement.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
  checkClosed();

  return new ClientParameterMetaData(this.parameterMetaData);
}
 
Example #12
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public void testRowValueConstructorBindParamMetaDataWithBindArgsOnLHSAndLiteralExprOnRHS() throws Exception {
    String query = "SELECT a_integer, x_integer FROM aTable WHERE (?, ?) = 7";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(2, pmd.getParameterCount());
    assertEquals(Integer.class.getName(), pmd.getParameterClassName(1));
    assertEquals(null, pmd.getParameterClassName(2));
}
 
Example #13
Source File: QueryMetaDataTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCoerceToDecimalArithmeticMetaData() throws Exception {
    String[] ops = { "+", "-", "*", "/" };
    for (String op : ops) {
        String query = "SELECT entity_id,a_string FROM atable where a_integer" + op + "2.5" + op + "?=0";
        Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, TestUtil.TEST_PROPERTIES);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setInt(1, 4);
        ParameterMetaData pmd = statement.getParameterMetaData();
        assertEquals(1, pmd.getParameterCount());
        assertEquals(BigDecimal.class.getName(), pmd.getParameterClassName(1));
    }
}
 
Example #14
Source File: EmbedCallableStatement30.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
   * JDBC 3.0
   *
   * Retrieves the number, types and properties of this PreparedStatement
   * object's parameters.
   *
   * @return a ParameterMetaData object that contains information about the
   * number, types and properties of this PreparedStatement object's parameters.
   * @exception SQLException if a database access error occurs
*/
public ParameterMetaData getParameterMetaData()
   throws SQLException
{
	checkStatus();
	if (preparedStatement == null)
		return null;
	
	return new EmbedParameterMetaData30(
			getParms(), preparedStatement.getParameterTypes());
}
 
Example #15
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testDateAdditionExpressionMetaData2() throws Exception {
    String query = "SELECT entity_id,a_string FROM atable where ?+a_date>a_date";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(1, pmd.getParameterCount());
    assertEquals(BigDecimal.class.getName(), pmd.getParameterClassName(1));
}
 
Example #16
Source File: DropSequenceCompiler.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public MutationPlan compile(final DropSequenceStatement sequence) throws SQLException {
    final PhoenixConnection connection = statement.getConnection();
    final MetaDataClient client = new MetaDataClient(connection);        
    final StatementContext context = new StatementContext(statement);
    return new MutationPlan() {           

        @Override
        public MutationState execute() throws SQLException {
            return client.dropSequence(sequence);
        }

        @Override
        public ExplainPlan getExplainPlan() throws SQLException {
            return new ExplainPlan(Collections.singletonList("DROP SEQUENCE"));
        }

        @Override
        public StatementContext getContext() {
            return context;
        }

        @Override
        public PhoenixConnection getConnection() {
            return connection;
        }

        @Override
        public ParameterMetaData getParameterMetaData() {                
            return PhoenixParameterMetaData.EMPTY_PARAMETER_META_DATA;
        }

    };
}
 
Example #17
Source File: ParameterMetaDataJdbc30Test.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
        *  test ParameterMetaData for Java procedures with DECIMAL parameters
 *
 * @exception SQLException if error occurs
        */
public void testParameterMetadataWithDECIMALParameters () throws SQLException {

	Statement stmt = createStatement();
      		stmt.execute("CREATE PROCEDURE PMDD(IN pmdI_1 DECIMAL(5,3), IN pmdI_2 DECIMAL(4,2), INOUT pmdI_3 DECIMAL(9,0), OUT pmdI_4 DECIMAL(10,2)) language java parameter style java external name 'org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMetaDataJdbc30Test.dummyDecimal'");
     		CallableStatement cs = prepareCall("CALL PMDD(?, ?, ?, ?)");

	// parameters 1 and 2 are input only
               cs.setBigDecimal(1,new BigDecimal("1"));;
               cs.setBigDecimal(2,new BigDecimal("1"));;
               // parameter 3 is input and output
               Object x = new BigDecimal(1.1);
               cs.setObject(3,x, Types.DECIMAL);
               cs.registerOutParameter(3,Types.DECIMAL);
               //parameter 4 is output only
               cs.registerOutParameter(4,Types.DECIMAL);
	//verify the meta data for the parameters
             	ParameterMetaData paramMetaData = cs.getParameterMetaData();
	assertEquals("Unexpected parameter count", 4, paramMetaData.getParameterCount());

	//expected values to be stored in a 2dim. array
               String parameterMetaDataArray0 [][] = {
               //isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
               {"PARAMETER_NULLABLE", "true", "5", "3", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_IN"},
               {"PARAMETER_NULLABLE", "true", "4", "2", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_IN"},
               {"PARAMETER_NULLABLE", "true", "9", "0", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_IN_OUT"},
               {"PARAMETER_NULLABLE", "true", "10", "2", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_OUT"}};

               testParameterMetaData(cs.getParameterMetaData(), parameterMetaDataArray0);

      		cs.close();
}
 
Example #18
Source File: PhoenixStatement.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public MutationPlan compilePlan(final PhoenixStatement stmt, Sequence.ValueOp seqAction) throws SQLException {
    final StatementContext context = new StatementContext(stmt);
    return new MutationPlan() {

        @Override
        public StatementContext getContext() {
            return context;
        }

        @Override
        public ParameterMetaData getParameterMetaData() {
            return PhoenixParameterMetaData.EMPTY_PARAMETER_META_DATA;
        }

        @Override
        public ExplainPlan getExplainPlan() throws SQLException {
            return new ExplainPlan(Collections.singletonList("UPDATE STATISTICS"));
        }

        @Override
        public PhoenixConnection getConnection() {
            return stmt.getConnection();
        }

        @Override
        public MutationState execute() throws SQLException {
            MetaDataClient client = new MetaDataClient(getConnection());
            return client.updateStatistics(ExecutableUpdateStatisticsStatement.this);
        }
    };
}
 
Example #19
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method validates translation map between clover record and prepared statement
 * 
 * @param transMap translation map to validate
 * @param statement prepared statement
 * @param inMetadata input metadata
 * @param jdbcSpecific jdbc specific for checking types
 * @return error message if map is invalid, null in other case
 * @throws SQLException
 */
public static List<String> validateJetel2sqlMap(CopySQLData[] transMap, PreparedStatement statement, 
	DataRecordMetadata inMetadata, JdbcSpecific jdbcSpecific) throws SQLException{
	List<String> messages = new ArrayList<String>();
	
	try {
		ParameterMetaData pMeta = statement.getParameterMetaData();
		if (transMap.length == pMeta.getParameterCount()) {
			for (int i = 0; i < transMap.length; i++) {
				if (!jdbcSpecific.isJetelTypeConvertible2sql(pMeta.getParameterType(i + 1), inMetadata.getField(transMap[i].getFieldJetel()))) {
					if (pMeta.getParameterType(i + 1) != Types.NULL) {
						messages.add("Invalid SQL query. Incompatible types - field " + inMetadata.getField(transMap[i].getFieldJetel()).getName() + ", clover type: " + inMetadata.getDataFieldType(transMap[i].getFieldJetel()).getName() + ", sql type: " + SQLUtil.sqlType2str(pMeta.getParameterType(i + 1)));
					} else {
						// MSSQL returns NULL parameter types
						break; // do not check the others
					}
				}
			}
		} else {
			messages.add("Invalid SQL query. Wrong number of parameteres - actually: " + transMap.length + ", required: " + pMeta.getParameterCount());
		}
	} catch (SQLException ex) {
		// S1C00 MySQL, 99999 Oracle
		if ("S1C00".equals(ex.getSQLState()) || "99999".equals(ex.getSQLState())) {
			// see CLO-8801 - Get rid of "Field compatibility cannot be verified warning" (https://bug.javlin.eu/browse/CLO-8801)
			// messages.add("Compatibility of field types could not have been validated (not supported by the driver).");
			// 42704 , 42P01 postgre
		} else if ("42704".equals(ex.getSQLState()) || "42P01".equals(ex.getSQLState())) {
			messages.add("Table does not exist.");
		} else {
			messages.add(ExceptionUtils.getMessage(ex));
		}
	}
	return messages;
}
 
Example #20
Source File: QueryMetaDataTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testRowValueConstructorBindParamMetaData() throws Exception {
    String query = "SELECT a_integer, x_integer FROM aTable WHERE (a_integer, x_integer, a_string) = (?, ?, ?)";
    Connection conn = DriverManager.getConnection(getUrl(), TestUtil.TEST_PROPERTIES);
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(3, pmd.getParameterCount());
    assertEquals(Integer.class.getName(), pmd.getParameterClassName(1));
    assertEquals(Integer.class.getName(), pmd.getParameterClassName(2));
    assertEquals(String.class.getName(), pmd.getParameterClassName(3));
}
 
Example #21
Source File: PhoenixStatement.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public MutationPlan compilePlan(final PhoenixStatement stmt, Sequence.ValueOp seqAction) throws SQLException {
    final StatementContext context = new StatementContext(stmt);
    return new MutationPlan() {
        
        @Override
        public StatementContext getContext() {
            return context;
        }

       @Override
        public ParameterMetaData getParameterMetaData() {
            return PhoenixParameterMetaData.EMPTY_PARAMETER_META_DATA;
        }
        
        @Override
        public ExplainPlan getExplainPlan() throws SQLException {
            return new ExplainPlan(Collections.singletonList("DROP INDEX"));
        }

        @Override
        public PhoenixConnection getConnection() {
            return stmt.getConnection();
        }

        @Override
        public MutationState execute() throws SQLException {
            MetaDataClient client = new MetaDataClient(getConnection());
            return client.dropIndex(ExecutableDropIndexStatement.this);
        }
    };
}
 
Example #22
Source File: QueryMetaDataTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testBindParamMetaDataForNestedRVC() throws Exception {
    String query = "SELECT organization_id, entity_id, a_string FROM aTable WHERE (organization_id, (entity_id, a_string)) >= (?, (?, ?))";
    Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, TestUtil.TEST_PROPERTIES);
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(3, pmd.getParameterCount());
    assertEquals(String.class.getName(), pmd.getParameterClassName(1));
    assertEquals(String.class.getName(), pmd.getParameterClassName(2));
    assertEquals(String.class.getName(), pmd.getParameterClassName(3));
}
 
Example #23
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoundParameterMetaData() throws Exception {
    String query = "SELECT a_string, b_string FROM atable WHERE round(a_date,'day', ?) = ?";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(2, pmd.getParameterCount());
    assertEquals(Integer.class.getName(), pmd.getParameterClassName(1));
    assertEquals(Date.class.getName(), pmd.getParameterClassName(2));
}
 
Example #24
Source File: CallableStatement.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.placeholderToParameterIndexMap == null) {
            return this.paramInfo;
        }

        return new CallableStatementParamInfo(this.paramInfo);
    }
}
 
Example #25
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testDateSubstractExpressionMetaData3() throws Exception {
    String query = "SELECT entity_id,a_string FROM atable where a_date-?=a_integer";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(1, pmd.getParameterCount());
    // FIXME: Should really be Integer, but we currently don't know if we're 
    // comparing to a date or a number where this is being calculated 
    // (which would disambiguate it).
    assertEquals(null, pmd.getParameterClassName(1));
}
 
Example #26
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeyPrefixParameterMetaData() throws Exception {
    String query = "SELECT a_string, b_string FROM atable WHERE organization_id='000000000000000' and substr(entity_id,1,3)=? and a_string = 'foo'";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(1, pmd.getParameterCount());
    assertEquals(String.class.getName(), pmd.getParameterClassName(1));
}
 
Example #27
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testDateSubstractExpressionMetaData2() throws Exception {
    String query = "SELECT entity_id,a_string FROM atable where a_date-?=a_date";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(1, pmd.getParameterCount());
    // FIXME: Should really be Date, but we currently don't know if we're 
    // comparing to a date or a number where this is being calculated 
    // (which would disambiguate it).
    assertEquals(null, pmd.getParameterClassName(1));
}
 
Example #28
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoDateSubstractExpressionMetaData() throws Exception {
    String query = "SELECT entity_id,a_string FROM atable where ?-a_date=1";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(1, pmd.getParameterCount());
    // We know this must be date - anything else would be an error
    assertEquals(Date.class.getName(), pmd.getParameterClassName(1));
}
 
Example #29
Source File: QueryMetaDataTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpsertParameterMetaData() throws Exception {
    String query = "UPSERT INTO atable VALUES (?, ?, ?, ?, ?)";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(5, pmd.getParameterCount());
    assertEquals(String.class.getName(), pmd.getParameterClassName(1));
    assertEquals(String.class.getName(), pmd.getParameterClassName(2));
    assertEquals(String.class.getName(), pmd.getParameterClassName(3));
    assertEquals(String.class.getName(), pmd.getParameterClassName(4));
    assertEquals(Integer.class.getName(), pmd.getParameterClassName(5));
}
 
Example #30
Source File: ProcedureTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testDataAwareProcedureWithoutResultSets()
throws SQLException {
  
  setup();
  CallableStatement cs = prepareCall("CALL PROCEDURE_WITHOUT_RESULTSET(?, ?) ON TABLE EMP.PARTITIONTESTTABLE WHERE SECONDID=4 AND THIRDID='3'");
  cs.registerOutParameter(2, java.sql.Types.VARCHAR, 20);
  int number=2;
  String name="INOUTPARAMETER";
  cs.setInt(1, number);
  cs.setString(2, name);
 
  
  cs.execute();
  
  ResultSet rs=cs.getResultSet();
  if(rs!=null || cs.getMoreResults()) {
    fail("no dynamic result set for the procedure!");
  }
  
  ParameterMetaData pmd=cs.getParameterMetaData();  
  int numParameters=pmd.getParameterCount();
  assertTrue(" the number of parameter is 2", numParameters==2);
  try {
    cs.getInt(1);
    fail("the in parameteter cannot be read!");
  } catch (Exception e) {
    
  }
  Object parameter2=cs.getObject(2);    
  assertTrue("the second inout parameter is "+name+number, parameter2.equals(name+number));
    
  

}