use of java.sql.ParameterMetaData in project phoenix by apache.
the class QueryMetaDataTest method testTwoDateSubstractExpressionMetaData.
@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));
}
use of java.sql.ParameterMetaData in project phoenix by apache.
the class QueryWithOffsetIT method testMetaDataWithOffset.
@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());
}
use of java.sql.ParameterMetaData in project phoenix by apache.
the class ParallelIteratorsSplitTest method getSplits.
private static List<KeyRange> getSplits(final TableRef tableRef, final Scan scan, final List<HRegionLocation> regions, final ScanRanges scanRanges) throws SQLException {
final List<TableRef> tableRefs = Collections.singletonList(tableRef);
ColumnResolver resolver = new ColumnResolver() {
@Override
public List<PFunction> getFunctions() {
return Collections.emptyList();
}
@Override
public List<TableRef> getTables() {
return tableRefs;
}
@Override
public TableRef resolveTable(String schemaName, String tableName) throws SQLException {
throw new UnsupportedOperationException();
}
@Override
public ColumnRef resolveColumn(String schemaName, String tableName, String colName) throws SQLException {
throw new UnsupportedOperationException();
}
@Override
public PFunction resolveFunction(String functionName) throws SQLException {
throw new UnsupportedOperationException();
}
@Override
public boolean hasUDFs() {
return false;
}
@Override
public PSchema resolveSchema(String schemaName) throws SQLException {
return null;
}
@Override
public List<PSchema> getSchemas() {
return null;
}
};
PhoenixConnection connection = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
final PhoenixStatement statement = new PhoenixStatement(connection);
final StatementContext context = new StatementContext(statement, resolver, scan, new SequenceManager(statement));
context.setScanRanges(scanRanges);
ParallelIterators parallelIterators = new ParallelIterators(new QueryPlan() {
private final Set<TableRef> tableRefs = ImmutableSet.of(tableRef);
@Override
public StatementContext getContext() {
return context;
}
@Override
public ParameterMetaData getParameterMetaData() {
return PhoenixParameterMetaData.EMPTY_PARAMETER_META_DATA;
}
@Override
public ExplainPlan getExplainPlan() throws SQLException {
return ExplainPlan.EMPTY_PLAN;
}
@Override
public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
return ResultIterator.EMPTY_ITERATOR;
}
@Override
public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
return ResultIterator.EMPTY_ITERATOR;
}
@Override
public ResultIterator iterator() throws SQLException {
return ResultIterator.EMPTY_ITERATOR;
}
@Override
public long getEstimatedSize() {
return 0;
}
@Override
public Set<TableRef> getSourceRefs() {
return tableRefs;
}
@Override
public TableRef getTableRef() {
return tableRef;
}
@Override
public RowProjector getProjector() {
return RowProjector.EMPTY_PROJECTOR;
}
@Override
public Integer getLimit() {
return null;
}
@Override
public Integer getOffset() {
return null;
}
@Override
public OrderBy getOrderBy() {
return OrderBy.EMPTY_ORDER_BY;
}
@Override
public GroupBy getGroupBy() {
return GroupBy.EMPTY_GROUP_BY;
}
@Override
public List<KeyRange> getSplits() {
return null;
}
@Override
public FilterableStatement getStatement() {
return SelectStatement.SELECT_ONE;
}
@Override
public boolean isDegenerate() {
return false;
}
@Override
public boolean isRowKeyOrdered() {
return true;
}
@Override
public List<List<Scan>> getScans() {
return null;
}
@Override
public Operation getOperation() {
return Operation.QUERY;
}
@Override
public boolean useRoundRobinIterator() {
return false;
}
@Override
public Long getEstimatedRowsToScan() {
return null;
}
@Override
public Long getEstimatedBytesToScan() {
return null;
}
}, null, new SpoolingResultIterator.SpoolingResultIteratorFactory(context.getConnection().getQueryServices()), context.getScan(), false);
List<KeyRange> keyRanges = parallelIterators.getSplits();
return keyRanges;
}
use of java.sql.ParameterMetaData in project spring-framework by spring-projects.
the class StatementCreatorUtilsTests method testSetParameterValueWithNullAndGetParameterTypeWorking.
@Test
public void testSetParameterValueWithNullAndGetParameterTypeWorking() throws SQLException {
ParameterMetaData pmd = mock(ParameterMetaData.class);
given(preparedStatement.getParameterMetaData()).willReturn(pmd);
given(pmd.getParameterType(1)).willReturn(Types.SMALLINT);
StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, null);
verify(pmd).getParameterType(1);
verify(preparedStatement, never()).getConnection();
verify(preparedStatement).setNull(1, Types.SMALLINT);
}
use of java.sql.ParameterMetaData in project jdbc-shards by wplatform.
the class PreparedStatementTestCase method testParameterMetaData.
private void testParameterMetaData(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("SELECT ?, ?, ? FROM DUAL");
ParameterMetaData pm = prep.getParameterMetaData();
assertEquals("java.lang.String", pm.getParameterClassName(1));
assertEquals("VARCHAR", pm.getParameterTypeName(1));
assertEquals(3, pm.getParameterCount());
assertEquals(ParameterMetaData.parameterModeIn, pm.getParameterMode(1));
assertEquals(Types.VARCHAR, pm.getParameterType(1));
assertEquals(0, pm.getPrecision(1));
assertEquals(0, pm.getScale(1));
assertEquals(ResultSetMetaData.columnNullableUnknown, pm.isNullable(1));
assertEquals(pm.isSigned(1), true);
assertThrows(ErrorCode.INVALID_VALUE_2, pm).getPrecision(0);
assertThrows(ErrorCode.INVALID_VALUE_2, pm).getPrecision(4);
prep.close();
assertThrows(ErrorCode.OBJECT_CLOSED, pm).getPrecision(1);
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST3(ID INT, " + "NAME VARCHAR(255), DATA DECIMAL(10,2))");
PreparedStatement prep1 = conn.prepareStatement("UPDATE TEST3 SET ID=?, NAME=?, DATA=?");
PreparedStatement prep2 = conn.prepareStatement("INSERT INTO TEST3 VALUES(?, ?, ?)");
checkParameter(prep1, 1, "java.lang.Integer", 4, "INTEGER", 10, 0);
checkParameter(prep1, 2, "java.lang.String", 12, "VARCHAR", 255, 0);
checkParameter(prep1, 3, "java.math.BigDecimal", 3, "DECIMAL", 10, 2);
checkParameter(prep2, 1, "java.lang.Integer", 4, "INTEGER", 10, 0);
checkParameter(prep2, 2, "java.lang.String", 12, "VARCHAR", 255, 0);
checkParameter(prep2, 3, "java.math.BigDecimal", 3, "DECIMAL", 10, 2);
PreparedStatement prep3 = conn.prepareStatement("SELECT * FROM TEST3 WHERE ID=? AND NAME LIKE ? AND ?>DATA");
checkParameter(prep3, 1, "java.lang.Integer", 4, "INTEGER", 10, 0);
checkParameter(prep3, 2, "java.lang.String", 12, "VARCHAR", 0, 0);
checkParameter(prep3, 3, "java.math.BigDecimal", 3, "DECIMAL", 10, 2);
stat.execute("DROP TABLE TEST3");
}
Aggregations