@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); }
@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); }
@Test public void testUsefulExceptionForBackTracing() throws Exception { Handle h = openHandle(); try { h.createStatement("insert-id-name").bind("id", 1).execute(); fail("should have raised an exception"); } catch (StatementException e) { assertTrue(e.getMessage().contains("insert into something(id, name) values (:id, :name)")); assertTrue(e.getMessage().contains("insert into something(id, name) values (?, ?)")); assertTrue(e.getMessage().contains("insert-id-name")); } }
@Test public void testNamedParamsInExternal() throws Exception { Handle h = openHandle(); h.createStatement("insert-id-name").bind("id", 1).bind("name", "Tip").execute(); assertEquals(1, h.select("select name from something").size()); }
@Test public void testLocateNamedWithoutSuffix() throws Exception { Handle h = openHandle(); h.createStatement("insert-keith").execute(); assertEquals(1, h.select("select name from something").size()); }