Search in sources :

Example 76 with ParameterMetaData

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

the class QueryMetaDataTest method testCaseMetaData.

@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));
}
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 77 with ParameterMetaData

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

the class QueryMetaDataTest method testDateAdditionExpressionMetaData2.

@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));
}
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 78 with ParameterMetaData

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

the class QueryMetaDataTest method testStringConcatMetaData.

@Test
public void testStringConcatMetaData() throws Exception {
    String query = "SELECT entity_id,a_string FROM atable where 2 || a_integer || ? like '2%'";
    Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    PreparedStatement statement = conn.prepareStatement(query);
    statement.setString(1, "foo");
    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 79 with ParameterMetaData

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

the class QueryMetaDataTest method testRowValueConstructorBindParamMetaDataWithBindArgsAtDiffPlacesOnLHSRHS.

@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));
}
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 80 with ParameterMetaData

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

the class QueryMetaDataTest method testRowValueConstructorBindParamMetaData.

@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(), 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(String.class.getName(), 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)136 PreparedStatement (java.sql.PreparedStatement)82 Test (org.junit.Test)55 Connection (java.sql.Connection)45 SQLException (java.sql.SQLException)35 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)31 ResultSet (java.sql.ResultSet)22 Statement (java.sql.Statement)20 ResultSetMetaData (java.sql.ResultSetMetaData)18 SQLServerParameterMetaData (com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData)15 BigDecimal (java.math.BigDecimal)12 CallableStatement (java.sql.CallableStatement)12 Test (org.junit.jupiter.api.Test)12 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)11 UnitTest (nl.topicus.jdbc.test.category.UnitTest)9 StringContains.containsString (org.hamcrest.core.StringContains.containsString)9 Date (java.sql.Date)7 DisplayName (org.junit.jupiter.api.DisplayName)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5