use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class CoalesceFunctionTest method coalesceTest.
@ParameterizedTest
@MethodSource("parametersForCoalesce")
void coalesceTest(String name, Function<Alias<WidgetRow>, CoalesceFunction<String>> f, String expected) {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
String sql = database.from(w).select(f.apply(w), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
assertThat(sql, is("select " + expected + " as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectExpressionTest method coalesceFunc.
@Test
void coalesceFunc() {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
String sql = database.from(w).select(coalesce(WidgetRow::name).orElse(WidgetRow::description).orElse("Bob"), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
assertThat(sql, is("select coalesce(w.NAME, w.DESCRIPTION, ?) as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectExpressionTest method substrFunc.
@Test
void substrFunc() {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
String sql = database.from(w).select(substr(w.column(WidgetRow::name), 4), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
assertThat(sql, is("select substr(w.NAME, ?) as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectExpressionTest method isIn.
@Test
void isIn() {
Database database = testDatabase(new AnsiDialect());
String sql = database.from(WidgetRow.class).where(WidgetRow::widgetId).isIn(123L, 456L).sql();
assertThat(sql, is("select WIDGET.WIDGET_ID as WIDGET_WIDGET_ID, " + "WIDGET.NAME as WIDGET_NAME, " + "WIDGET.MANUFACTURER_ID as WIDGET_MANUFACTURER_ID, " + "WIDGET.DESCRIPTION as WIDGET_DESCRIPTION " + "from SIESTA.WIDGET WIDGET " + "where WIDGET.WIDGET_ID in (?, ?)"));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectExpressionTest method isLikeEscape.
@Test
void isLikeEscape() {
Database database = testDatabase(new AnsiDialect());
String sql = database.from(WidgetRow.class).where(WidgetRow::name).isLike("abc@%%", "@").sql();
assertThat(sql, is("select WIDGET.WIDGET_ID as WIDGET_WIDGET_ID, " + "WIDGET.NAME as WIDGET_NAME, " + "WIDGET.MANUFACTURER_ID as WIDGET_MANUFACTURER_ID, " + "WIDGET.DESCRIPTION as WIDGET_DESCRIPTION " + "from SIESTA.WIDGET WIDGET " + "where WIDGET.NAME like ? escape '@'"));
}
Aggregations