use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class SelectExpressionTest method concat.
@Test
void concat() {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
String sql = database.from(w).select(w.column(WidgetRow::name).concat(WidgetRow::description).concat(WidgetRow::manufacturerId), "name").where(w.column(WidgetRow::name).concat(WidgetRow::description).isEqualTo(value("Bob").concat(w.column(WidgetRow::description)))).sql();
assertThat(sql, is("select w.NAME || w.DESCRIPTION || w.MANUFACTURER_ID as name " + "from SIESTA.WIDGET w " + "where w.NAME || w.DESCRIPTION = ? || w.DESCRIPTION"));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class SelectExpressionTest method orExpression.
@Test
void orExpression() {
Database database = testDatabase(new AnsiDialect());
Alias<ManufacturerRow> m = database.table(ManufacturerRow.class).as("m");
String sql = database.from(m).where(column(ManufacturerRow::checked).isLessThan(LocalDate.now()).or(ManufacturerRow::checked).isGreaterThan(LocalDate.now()).or(ManufacturerRow::name).isEqualTo("Fred")).and(column(ManufacturerRow::name).isEqualTo("Bob").or(ManufacturerRow::checked).isNull()).sql();
assertThat(sql, is("select m.MANUFACTURER_ID as m_MANUFACTURER_ID, m.NAME as m_NAME, m.CHECKED as m_CHECKED " + "from SIESTA.MANUFACTURER m " + "where (m.CHECKED < cast(? as date) or m.CHECKED > cast(? as date) or m.NAME = ?) " + "and (m.NAME = ? or m.CHECKED is null)"));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class SelectGroupByTest method groupBy1.
@Test
void groupBy1() {
Database database = TestDatabase.testDatabase(new AnsiDialect());
database.from(WidgetRow.class, "w").select(WidgetRow::manufacturerId).comma(max(WidgetRow::name)).groupBy(WidgetRow::manufacturerId).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select w.MANUFACTURER_ID as w_MANUFACTURER_ID, max(w.NAME) as max_w_NAME " + "from SIESTA.WIDGET w " + "group by w.MANUFACTURER_ID"));
assertThat(args.getValue(), arrayWithSize(0));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class SelectGroupByTest method groupBy2.
@Test
void groupBy2() {
Database database = TestDatabase.testDatabase(new AnsiDialect());
database.from(WidgetRow.class, "w").select(WidgetRow::manufacturerId).comma(WidgetRow::description).comma(max(WidgetRow::name)).groupBy(WidgetRow::manufacturerId).comma(WidgetRow::description).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select w.MANUFACTURER_ID as w_MANUFACTURER_ID, w.DESCRIPTION as w_DESCRIPTION, max(w.NAME) as max_w_NAME " + "from SIESTA.WIDGET w " + "group by w.MANUFACTURER_ID, w.DESCRIPTION"));
assertThat(args.getValue(), arrayWithSize(0));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class BetweenBuilderTest method and.
@ParameterizedTest
@MethodSource("argsForAnd")
void and(BiFunction<BetweenBuilder<String, InWhereExpectingAnd<String>>, Alias<SalespersonRow>, InWhereExpectingAnd<String>> method, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
BetweenBuilder<String, InWhereExpectingAnd<String>> between = database.from(alias).select(SalespersonRow::firstName, "name").where(SalespersonRow::firstName).isBetween(SalespersonRow::middleNames);
method.apply(between, alias).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select s.FIRST_NAME as name from SIESTA.SALESPERSON s where s.FIRST_NAME between s.MIDDLE_NAMES and " + expectedSql));
assertThat(args.getValue(), is(expectedArgs));
}
Aggregations