use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestClasspathSqlLocator method testNamedParamsInExternal.
@Test
public void testNamedParamsInExternal() throws Exception {
Handle h = dbRule.openHandle();
h.createUpdate(findSqlOnClasspath("insert-id-name")).bind("id", 1).bind("name", "Tip").execute();
assertThat(h.select("select name from something").mapTo(String.class).list()).hasSize(1);
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestRegisteredMappers method testRegisterInferredOnJdbi.
@Test
public void testRegisterInferredOnJdbi() throws Exception {
db.registerRowMapper(new SomethingMapper());
Something sam = db.withHandle(handle1 -> {
handle1.execute("insert into something (id, name) values (18, 'Sam')");
return handle1.createQuery("select id, name from something where id = :id").bind("id", 18).mapTo(Something.class).findOnly();
});
assertThat(sam.getName()).isEqualTo("Sam");
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestPositionalParameterBinding method testSetPositionalString.
@Test
public void testSetPositionalString() throws Exception {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
Something eric = h.createQuery("select * from something where name = ?").bind(0, "eric").mapToBean(Something.class).list().get(0);
assertThat(eric.getId()).isEqualTo(1);
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestStatementContext method testFoo.
@Test
public void testFoo() throws Exception {
Handle h = dbRule.openHandle();
final int inserted = h.createUpdate("insert into <table> (id, name) values (:id, :name)").bind("id", 7).bind("name", "Martin").define("table", "something").execute();
assertThat(inserted).isEqualTo(1);
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestTimingCollector method testUpdate.
@Test
public void testUpdate() throws Exception {
String stmt1 = "insert into something (id, name) values (1, 'eric')";
String stmt2 = "update something set name = :name where id = :id";
String stmt3 = "select * from something where id = :id";
h.execute(stmt1);
h.createUpdate(stmt2).bind("id", 1).bind("name", "ERIC").execute();
Something eric = h.createQuery(stmt3).bind("id", 1).mapToBean(Something.class).list().get(0);
assertThat(eric.getName()).isEqualTo("ERIC");
assertThat(tc.getRawStatements()).containsExactly(stmt1, stmt2, stmt3);
assertThat(tc.getRenderedStatements()).containsExactly(stmt1, stmt2, stmt3);
assertThat(tc.getParsedStatements()).extracting("sql").containsExactly(stmt1, "update something set name = ? where id = ?", "select * from something where id = ?");
}
Aggregations