use of mondrian.spi.impl.JdbcDialectImpl in project mondrian by pentaho.
the class DialectTest method testDateLiteralString.
public void testDateLiteralString() {
// verify correct construction of the date literal string.
// With Oracle this can get interesting, because depending on the
// driver version the string may be a DATE or a TIMESTAMP.
// We need to construct a valid date literal in either case.
// See http://jira.pentaho.com/browse/MONDRIAN-1819 and
// http://jira.pentaho.com/browse/MONDRIAN-626
//
// verify jdbc dialect - some jdbc drivers return TIMESTAMP too
// http://jira.pentaho.com/browse/MONDRIAN-2038
Dialect jdbcDialect = new JdbcDialectImpl();
StringBuilder buf = new StringBuilder();
jdbcDialect.quoteDateLiteral(buf, "2003-12-12");
assertEquals("DATE '2003-12-12'", buf.toString());
buf = new StringBuilder();
jdbcDialect.quoteDateLiteral(buf, "2007-01-15 00:00:00.0");
assertEquals("DATE '2007-01-15'", buf.toString());
if (getDialect().getDatabaseProduct() != Dialect.DatabaseProduct.ORACLE) {
// the following test is specifically for Oracle.
return;
}
final TestContext context = TestContext.instance().withSchema("<?xml version=\"1.0\"?>\n" + "<Schema name=\"FoodMart\">\n" + " <Dimension name=\"Time\" type=\"TimeDimension\">\n" + " <Hierarchy hasAll='true' primaryKey=\"time_id\">\n" + " <Table name=\"time_by_day\"/>\n" + " <Level name=\"Day\" type=\"Date\" uniqueMembers=\"true\"\n" + " levelType=\"TimeYears\">\n" + " <KeyExpression>\n" + " <SQL>\n" + " cast(\"the_date\" as DATE)\n" + " </SQL>\n" + " </KeyExpression>\n" + " </Level>\n" + " </Hierarchy>\n" + " </Dimension>\n" + " <Cube name=\"DateLiteralTest\" defaultMeasure=\"expression\">\n" + " <Table name=\"sales_fact_1997\" />\n" + " <DimensionUsage name=\"Time\" source=\"Time\" foreignKey=\"time_id\"/>\n" + " <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"\n" + " formatString=\"Standard\" />\n" + " </Cube>\n" + "</Schema>\n");
// if date literal is incorrect the following query will give the error
// ORA-01861: literal does not match format string
Result result = context.executeQuery("select Time.[All Times].FirstChild on 0 from DateLiteralTest");
String firstChild = result.getAxes()[0].getPositions().get(0).get(0).getName().toString();
// the member name may have timestamp info, for example if using
// Oracle with ojdbc5+. Make sure it starts w/ the expected date.
assertTrue(firstChild.startsWith("1997-01-01"));
}
use of mondrian.spi.impl.JdbcDialectImpl in project mondrian by pentaho.
the class DialectTest method testMondrian2253.
public void testMondrian2253() throws SQLException {
String expected = " 1 ASC";
// "1" is supposed to be a column number
String expr = "1";
JdbcDialectImpl dialect = new VectorwiseDialect(getConnection());
SqlQuery query = new SqlQuery(dialect, true);
query.addOrderBy(expr, null, true, false, dialect.requiresUnionOrderByOrdinal(), true);
assertTrue(query.toString().contains(expected));
}
use of mondrian.spi.impl.JdbcDialectImpl in project mondrian by pentaho.
the class DialectTest method testJdbcDialectTypeMap.
public void testJdbcDialectTypeMap() throws SQLException {
MockResultSetMetadata mockResultSetMeta = new MockResultSetMetadata();
Dialect postgresDialect = new JdbcDialectImpl();
assertTrue("JdbcDialectImpl NUMERIC/DECIMAL types w/ precision 0-9" + " and scale=0 should return INT", postgresDialect.getType(mockResultSetMeta.withColumnType(Types.NUMERIC).withPrecision(5).withScale(0).build(), 0) == SqlStatement.Type.INT);
assertTrue("JdbcDialectImpl NUMERIC/DECIMAL types w/ precision 0-9" + " and scale=0 should return INT", postgresDialect.getType(mockResultSetMeta.withColumnType(Types.DECIMAL).withPrecision(5).withScale(0).build(), 0) == SqlStatement.Type.INT);
}
Aggregations