Java Code Examples for java.sql.ParameterMetaData

The following examples show how to use java.sql.ParameterMetaData. These examples are extracted from open source projects. 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 Project: snowflake-jdbc   Source File: PreparedStatement2IT.java    License: 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 2
Source Project: spliceengine   Source File: UDTTest.java    License: 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 3
Source Project: gemfirexd-oss   Source File: ParameterMetaDataJdbc30Test.java    License: 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 4
Source Project: phoenix   Source File: PhoenixPreparedStatement.java    License: 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 5
Source Project: phoenix   Source File: QueryMetaDataTest.java    License: 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 6
Source Project: gemfirexd-oss   Source File: ParameterMetaDataJdbc30Test.java    License: 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 Project: phoenix   Source File: QueryWithOffsetIT.java    License: 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 8
Source Project: phoenix   Source File: UnionPlan.java    License: 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 9
Source Project: gemfirexd-oss   Source File: UDTTest.java    License: 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 Project: phoenix   Source File: QueryMetaDataTest.java    License: 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 11
Source Project: phoenix   Source File: QueryMetaDataTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRowValueConstructorBindParamMetaDataWithLessNumberOfBindArgs() throws Exception {
    String query = "SELECT a_integer, x_integer FROM aTable WHERE (a_integer, x_integer, a_string) = (?, ?)";
    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(Integer.class.getName(), pmd.getParameterClassName(2));
}
 
Example 12
Source Project: gemfirexd-oss   Source File: ParameterMetaDataJdbc30Test.java    License: Apache License 2.0 5 votes vote down vote up
/** 
        * testing SELECT statements for BOOLEANs (1 for true, 0 for false) 
 *
 * @exception SQLException if error occurs
 */ 
public void testSelectStatementUsingBoolean () throws SQLException {

	/*
	 * Bug 4654 - Null Pointer exception while executuing a select with a
        	 * where clause parameter of type 'TRUE' or 'FALSE' constants. The existing prior to
        	 * exposing parameter metadata didn't need to fill in metadata information for where
        	 * clause parameter in the example above.
        	 * This no longer makes sense, for we cannot take BOOLEANs anymore.
        	 * replace with a simple where 1 = ?. Which would take either 1 for true, or 0 for false
	 */
     		PreparedStatement ps = prepareStatement("select * from t "+  
						"where 1=? for update");

     		ParameterMetaData paramMetaData = ps.getParameterMetaData();
	assertEquals("Unexpected parameter count", 1, paramMetaData.getParameterCount());

	//expected values to be stored in a 2dim. array
               String parameterMetaDataArray0 [][] = {
               //isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
               {"PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN"}};

               testParameterMetaData(paramMetaData, parameterMetaDataArray0);

     		dumpParameterMetaDataNegative(paramMetaData);
     		ps.setInt(1,1);
     		ps.execute();

	ps.close();
}
 
Example 13
Source Project: gemfirexd-oss   Source File: ProcedureTest.java    License: 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));
    
  

}
 
Example 14
Source Project: gemfirexd-oss   Source File: ParameterMetaDataJdbc30Test.java    License: Apache License 2.0 5 votes vote down vote up
/**
        * print the parameter mode in human readable form
        *
        * @param mode identifies parameter's mode (IN, OUT, or IN_OUT)
 * @return     the parameter mode in readable form
        *             
        */
static String parameterModeInStringForm(int mode){
	if (mode ==  ParameterMetaData.parameterModeIn)
			  return("PARAMETER_MODE_IN");
	else if (mode ==  ParameterMetaData.parameterModeInOut )
			  return("PARAMETER_MODE_IN_OUT");
	else if (mode ==  ParameterMetaData.parameterModeOut)
			  return("PARAMETER_MODE_OUT");
	else if (mode ==  ParameterMetaData.parameterModeUnknown)
			  return("PARAMETER_MODE_UNKNOWN");
	else
			  return("ERROR: donot recognize this parameter mode");
 	}
 
Example 15
@Test
public void testCaseInsensitive() throws Exception {
    String query = "SELECT A_string, b_striNG FROM ataBle WHERE ORGANIZATION_ID='000000000000000'";
    Connection conn = DriverManager.getConnection(getUrl(), TestUtil.TEST_PROPERTIES);
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(0, pmd.getParameterCount());
}
 
Example 16
/** 
        * testing SELECT statements for BOOLEANs (1 for true, 0 for false) 
 *
 * @exception SQLException if error occurs
 */ 
public void testSelectStatementUsingBoolean () throws SQLException {

	/*
	 * Bug 4654 - Null Pointer exception while executuing a select with a
        	 * where clause parameter of type 'TRUE' or 'FALSE' constants. The existing prior to
        	 * exposing parameter metadata didn't need to fill in metadata information for where
        	 * clause parameter in the example above.
        	 * This no longer makes sense, for we cannot take BOOLEANs anymore.
        	 * replace with a simple where 1 = ?. Which would take either 1 for true, or 0 for false
	 */
     		PreparedStatement ps = prepareStatement("select * from t "+  
						"where 1=? for update");

     		ParameterMetaData paramMetaData = ps.getParameterMetaData();
	assertEquals("Unexpected parameter count", 1, paramMetaData.getParameterCount());

	//expected values to be stored in a 2dim. array
               String parameterMetaDataArray0 [][] = {
               //isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
               {"PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN"}};

               testParameterMetaData(paramMetaData, parameterMetaDataArray0);

     		dumpParameterMetaDataNegative(paramMetaData);
     		ps.setInt(1,1);
     		ps.execute();

	ps.close();
}
 
Example 17
Source Project: phoenix   Source File: QueryMetaDataTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRowValueConstructorBindParamMetaDataWithBindArgsAtDiffPlacesOnLHSRHS() throws Exception {
    String query = "SELECT a_integer, x_integer FROM aTable WHERE (a_integer, ?) = (?, a_integer)";
    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(Integer.class.getName(), pmd.getParameterClassName(2));
}
 
Example 18
Source Project: gemfirexd-oss   Source File: ParameterMetaDataJdbc30Test.java    License: Apache License 2.0 5 votes vote down vote up
/**
        * test ParameterMetaData for Java procedures with INTEGER parameters 
 * 
 * @exception SQLException if error occurs
        */
public void testParameterMetadataWithINTParameters () throws SQLException {

	Statement stmt = createStatement();
      		stmt.execute("CREATE PROCEDURE PMDI(IN pmdI_1 INTEGER, IN pmdI_2 INTEGER, INOUT pmdI_3 INTEGER, OUT pmdI_4 INTEGER) language java parameter style java external name 'org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMetaDataJdbc30Test.dummyint'");
     		CallableStatement cs = prepareCall("CALL PMDI(?, ?, ?, ?)");

	// parameters 1 and 2 are input only
              	cs.setInt(1,1);
       	cs.setInt(2,1);
	// parameter 3 is input and output
               Object x = new Integer(1);
               cs.setObject(3,x, Types.INTEGER);
               cs.registerOutParameter(3,Types.INTEGER);
              	//parameter 4 is output only
              	cs.registerOutParameter(4,Types.INTEGER);

              	//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", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN"},
               {"PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN"},
               {"PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN_OUT"},
               {"PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_OUT"}};

               testParameterMetaData(cs.getParameterMetaData(), parameterMetaDataArray0);
		
      		cs.close();
      		stmt.execute("DROP PROCEDURE PMDI");
           stmt.close();
}
 
Example 19
Source Project: jsqsh   Source File: SQLTools.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Decodes a parameter mode number into a readable string
 * @param mode The mode
 * @return The string
 */
public static String getParameterMode(int mode) {
    
    switch (mode) {
    case ParameterMetaData.parameterModeIn: return "IN";
    case ParameterMetaData.parameterModeInOut: return "INOUT";
    case ParameterMetaData.parameterModeOut: return "OUT";
    case ParameterMetaData.parameterModeUnknown: return "UNKNOWN";
    default:
        return "UNRECOGNIZED";
    }
}
 
Example 20
Source Project: gemfirexd-oss   Source File: ClientPreparedStatement.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
  checkClosed();

  return new ClientParameterMetaData(this.parameterMetaData);
}
 
Example 21
/**
 *  get parameter scale or DB2 max (38)
 *
 *  @param index parameter index starting with 1
 *
 *  @return  scale
 */
protected int getParamScale(int index) throws SQLException
{
	if (ps != null && ps instanceof CallableStatement)
	{
		ParameterMetaData pmeta = getParameterMetaData();
		return Math.min(pmeta.getScale(index),FdocaConstants.NUMERIC_MAX_PRECISION);
	}
	else 
		return -1;
}
 
Example 22
Source Project: gemfirexd-oss   Source File: ParameterMetaDataJdbc30Test.java    License: Apache License 2.0 5 votes vote down vote up
/**
        * test ParameterMetaData for Java procedures with CHAR parameters
 *
 * @exception SQLException if error occurs
        */
 public void testParameterMetadataWithCHARParameters () throws SQLException {

	Statement stmt = createStatement();
      		stmt.execute("CREATE PROCEDURE PMDC(IN pmdI_1 CHAR(10), IN pmdI_2 VARCHAR(25), INOUT pmdI_3 CHAR(19), OUT pmdI_4 VARCHAR(32)) language java parameter style java external name 'org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMetaDataJdbc30Test.dummyString'");
     		CallableStatement cs = prepareCall("CALL PMDC(?, ?, ?, ?)");
	// parameters 1 and 2 are input only	
	cs.setString(1, "TEST0");
	cs.setString(2, "TEST1");
	// parameter 3 is input and output
               Object x = new String("TEST");
               cs.setObject(3,x, Types.CHAR);
               cs.registerOutParameter(3,Types.CHAR);
               //parameter 4 is output only
               cs.registerOutParameter(4,Types.CHAR);
		//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", "false", "10", "0", "1", "CHAR", "java.lang.String", "PARAMETER_MODE_IN"},
               {"PARAMETER_NULLABLE", "false", "25", "0", "12", "VARCHAR", "java.lang.String", "PARAMETER_MODE_IN"},
               {"PARAMETER_NULLABLE", "false", "19", "0", "1", "CHAR", "java.lang.String", "PARAMETER_MODE_IN_OUT"},
               {"PARAMETER_NULLABLE", "false", "32", "0", "12", "VARCHAR", "java.lang.String", "PARAMETER_MODE_OUT"}};

	testParameterMetaData(cs.getParameterMetaData(), parameterMetaDataArray0);

      		cs.close();
      		stmt.execute("DROP PROCEDURE PMDC");
           stmt.close();
}
 
Example 23
public ParameterMetaData getParameterMetaData() throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((PreparedStatement) this.wrappedStmt).getParameterMetaData();
        }

        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return null;
}
 
Example 24
Source Project: lams   Source File: CallableStatement.java    License: 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 Project: phoenix   Source File: QueryMetaDataTest.java    License: 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 26
Source Project: gemfirexd-oss   Source File: ProcedureTest.java    License: 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));
    
  

}
 
Example 27
Source Project: phoenix   Source File: QueryMetaDataTest.java    License: 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 28
Source Project: phoenix   Source File: QueryMetaDataTest.java    License: 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 29
Source Project: phoenix   Source File: QueryMetaDataTest.java    License: 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 30
Source Project: phoenix   Source File: QueryMetaDataTest.java    License: 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));
}