Search in sources :

Example 21 with ParameterMetaData

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

the class QueryMetaDataTest method testInListParameterMetaData1.

@Test
public void testInListParameterMetaData1() throws Exception {
    String query = "SELECT a_string, b_string FROM atable WHERE a_string IN (?, ?)";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(2, pmd.getParameterCount());
    assertEquals(String.class.getName(), pmd.getParameterClassName(1));
    assertEquals(String.class.getName(), pmd.getParameterClassName(2));
}
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 22 with ParameterMetaData

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

the class QueryMetaDataTest method testCaseInsensitive.

@Test
public void testCaseInsensitive() throws Exception {
    String query = "SELECT A_string, b_striNG FROM ataBle WHERE ORGANIZATION_ID='000000000000000'";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    ParameterMetaData pmd = statement.getParameterMetaData();
    assertEquals(0, pmd.getParameterCount());
}
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 23 with ParameterMetaData

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

the class QueryMetaDataTest method testLongArithmeticMetaData.

@Test
public void testLongArithmeticMetaData() throws Exception {
    String[] ops = { "+", "-", "*", "/" };
    for (String op : ops) {
        String query = "SELECT entity_id,a_string FROM atable where a_integer" + op + "2" + op + "?=0";
        Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setInt(1, 4);
        ParameterMetaData pmd = statement.getParameterMetaData();
        assertEquals(1, pmd.getParameterCount());
        assertEquals(Long.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 24 with ParameterMetaData

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

the class QueryMetaDataTest method testInListParameterMetaData3.

@Test
public void testInListParameterMetaData3() throws Exception {
    String query = "SELECT a_string, b_string FROM atable WHERE ? IN ('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));
}
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 25 with ParameterMetaData

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

the class QueryMetaDataTest method testCoerceToDecimalArithmeticMetaData.

@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(getUrl(), PropertiesUtil.deepCopy(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));
    }
}
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)

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