Search in sources :

Example 41 with ParameterMetaData

use of java.sql.ParameterMetaData in project phoenix by apache.

the class SequenceIT method testValidateBeforeReserve.

@Test
public void testValidateBeforeReserve() throws Exception {
    nextConnection();
    conn.createStatement().execute("CREATE TABLE foo (k VARCHAR PRIMARY KEY, l BIGINT)");
    conn.createStatement().execute("CREATE SEQUENCE foo.bar");
    nextConnection();
    ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT NEXT VALUE FOR foo.bar FROM foo");
    assertTrue(rs.next());
    conn.createStatement().execute("UPSERT INTO foo VALUES ('a', NEXT VALUE FOR foo.bar)");
    conn.createStatement().execute("UPSERT INTO foo VALUES ('b', NEXT VALUE FOR foo.bar)");
    conn.commit();
    nextConnection();
    rs = conn.createStatement().executeQuery("SELECT * FROM foo");
    assertTrue(rs.next());
    assertEquals("a", rs.getString(1));
    assertEquals(1, rs.getLong(2));
    assertTrue(rs.next());
    assertEquals("b", rs.getString(1));
    assertEquals(2, rs.getLong(2));
    assertFalse(rs.next());
    nextConnection();
    PreparedStatement stmt = conn.prepareStatement("SELECT NEXT VALUE FOR foo.bar FROM foo");
    ParameterMetaData md = stmt.getParameterMetaData();
    assertEquals(0, md.getParameterCount());
    rs = stmt.executeQuery();
    assertTrue(rs.next());
    assertEquals(3, rs.getLong(1));
    assertTrue(rs.next());
    assertEquals(4, rs.getLong(1));
    assertFalse(rs.next());
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ParameterMetaData(java.sql.ParameterMetaData) Test(org.junit.Test)

Example 42 with ParameterMetaData

use of java.sql.ParameterMetaData in project phoenix by apache.

the class QueryMetaDataTest method testInListParameterMetaData2.

@Test
public void testInListParameterMetaData2() throws Exception {
    String query = "SELECT a_string, b_string FROM atable WHERE ? IN (2.2, 3)";
    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));
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ParameterMetaData(java.sql.ParameterMetaData) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 43 with ParameterMetaData

use of java.sql.ParameterMetaData in project phoenix by apache.

the class QueryMetaDataTest method testToDateFunctionMetaData.

@Test
public void testToDateFunctionMetaData() throws Exception {
    String query = "SELECT a_string, b_string FROM atable WHERE a_date > to_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(String.class.getName(), pmd.getParameterClassName(1));
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ParameterMetaData(java.sql.ParameterMetaData) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 44 with ParameterMetaData

use of java.sql.ParameterMetaData in project phoenix by apache.

the class QueryMetaDataTest method testDateSubstractExpressionMetaData2.

@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));
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ParameterMetaData(java.sql.ParameterMetaData) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 45 with ParameterMetaData

use of java.sql.ParameterMetaData in project phoenix by apache.

the class QueryMetaDataTest method testRowValueConstructorBindParamMetaDataWithMoreNumberOfBindArgs.

@Test
public void testRowValueConstructorBindParamMetaDataWithMoreNumberOfBindArgs() throws Exception {
    String query = "SELECT a_integer, x_integer FROM aTable WHERE (a_integer, x_integer) = (?, ?, ?)";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(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(null, pmd.getParameterClassName(3));
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ParameterMetaData(java.sql.ParameterMetaData) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

ParameterMetaData (java.sql.ParameterMetaData)58 PreparedStatement (java.sql.PreparedStatement)49 Test (org.junit.Test)41 Connection (java.sql.Connection)39 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)31 ResultSet (java.sql.ResultSet)14 ResultSetMetaData (java.sql.ResultSetMetaData)10 Statement (java.sql.Statement)9 StringContains.containsString (org.hamcrest.core.StringContains.containsString)9 BigDecimal (java.math.BigDecimal)8 Date (java.sql.Date)6 SQLException (java.sql.SQLException)6 Calendar (java.util.Calendar)2 List (java.util.List)2 Set (java.util.Set)2 TimeZone (java.util.TimeZone)2 Scan (org.apache.hadoop.hbase.client.Scan)2 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)1 FilterChain (com.alibaba.druid.filter.FilterChain)1 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1