From 1447cf7a3f334873d2b5d407681f1be0aa91328c Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sat, 10 Dec 2011 16:45:00 +0000 Subject: [PATCH] [#981] Cannot insertInto(table("my_table")), as plain SQL tables return Table, not Table. Relax bound on R - Added integration tests --- .../src/org/jooq/test/jOOQAbstractTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java index 09fbb558c9..233f9d9acc 100644 --- a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java +++ b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java @@ -1555,6 +1555,71 @@ public abstract class jOOQAbstractTest< assertEquals(Integer.valueOf(1), books.getValue(1, TBook_AUTHOR_ID())); } + @Test + public void testPlainSQLCRUD() throws Exception { + reset = false; + + // CRUD with plain SQL + Table table = table(TAuthor().getName()); + Field id = field(TAuthor_ID().getName()); + Field firstName = field(TAuthor_FIRST_NAME().getName()); + Field lastName = field(TAuthor_LAST_NAME().getName()); + + assertEquals(2, + create().insertInto(table, id, firstName, lastName) + .values(10, "Herbert", "Meier") + .values(11, "Friedrich", "Glauser") + .execute()); + + Result authors1 = create() + .select(id, firstName, lastName) + .from(table) + .where(id.in(10, 11)) + .orderBy(id) + .fetch(); + + assertEquals(2, authors1.size()); + assertEquals(10, authors1.getValue(0, id)); + assertEquals(11, authors1.getValue(1, id)); + assertEquals("Herbert", authors1.getValue(0, firstName)); + assertEquals("Friedrich", authors1.getValue(1, firstName)); + assertEquals("Meier", authors1.getValue(0, lastName)); + assertEquals("Glauser", authors1.getValue(1, lastName)); + + assertEquals(2, + create().update(table) + .set(firstName, "Friedrich") + .set(lastName, "Schiller") + .where(id.in(10, 11)) + .execute()); + + Result authors2 = + create().select(id, firstName, lastName) + .from(table) + .where(id.in(10, 11)) + .orderBy(id) + .fetch(); + + assertEquals(2, authors2.size()); + assertEquals(10, authors2.getValue(0, id)); + assertEquals(11, authors2.getValue(1, id)); + assertEquals("Friedrich", authors2.getValue(0, firstName)); + assertEquals("Friedrich", authors2.getValue(1, firstName)); + assertEquals("Schiller", authors2.getValue(0, lastName)); + assertEquals("Schiller", authors2.getValue(1, lastName)); + + assertEquals(2, + create().delete(table) + .where(id.in(10, 11)) + .execute()); + + assertEquals(0, + create().selectCount() + .from(table) + .where(id.in(10, 11)) + .fetchOne(0)); + } + @Test public void testCustomSQL() throws Exception { final Field IDx2 = new CustomField(TBook_ID().getName(), TBook_ID().getDataType()) {