@Test public void testDelete() throws Exception { Handle h = openHandle(); Update insert = h.createStatement("insert into something_else (name) values (:name)"); insert.bind("name", "Brian"); Long id1 = insert.executeAndReturnGeneratedKeys(LongColumnMapper.WRAPPER).first(); Assert.assertNotNull(id1); Update delete = h.createStatement("delete from something_else where id = :id"); delete.bind("id", id1); Long id2 = delete.executeAndReturnGeneratedKeys(LongColumnMapper.WRAPPER).first(); Assert.assertNull(id2); }
public int update(String sql, Object... args) { Update stmt = createStatement(sql); int position = 0; for (Object arg : args) { stmt.bind(position++, arg); } return stmt.execute(); }
@Test public void testInsert() throws Exception { Handle h = openHandle(); Update insert1 = h.createStatement("insert into something_else (name) values (:name)"); insert1.bind("name", "Brian"); Long id1 = insert1.executeAndReturnGeneratedKeys(LongColumnMapper.WRAPPER).first(); Assert.assertNotNull(id1); Update insert2 = h.createStatement("insert into something_else (name) values (:name)"); insert2.bind("name", "Tom"); Long id2 = insert2.executeAndReturnGeneratedKeys(LongColumnMapper.WRAPPER).first(); Assert.assertNotNull(id2); Assert.assertTrue(id2 > id1); }