From ea6f3a0b280112b961ad4ca15514349f643bbfc4 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sat, 25 Aug 2012 16:30:50 +0200 Subject: [PATCH] [#1657] Reorganise the manual (152 / 174) --- .../src/main/resources/manual-2.5.xml | 136 +++++++++++++++--- 1 file changed, 113 insertions(+), 23 deletions(-) diff --git a/jOOQ-website/src/main/resources/manual-2.5.xml b/jOOQ-website/src/main/resources/manual-2.5.xml index 1c9a5438e3..ba9d138f3b 100644 --- a/jOOQ-website/src/main/resources/manual-2.5.xml +++ b/jOOQ-website/src/main/resources/manual-2.5.xml @@ -2448,7 +2448,76 @@ Table naturalRightOuterJoin(TableLike)]]>
Nested SELECTs - + +

Nested SELECTs, subqueries, derived tables

+

+ A can appear almost anywhere a can. Such a "nested SELECT" is often called a "derived table". Apart from many convenience methods accepting objects directly, a SELECT statement can always be transformed into a object using the asTable() method. +

+ +

Example: Scalar subquery

+ + +SELECT * + FROM BOOK + WHERE BOOK.AUTHOR_ID = ( + SELECT ID + FROM AUTHOR + WHERE LAST_NAME = 'Orwell') +create.select() + .from(BOOK) + .where(BOOK.AUTHOR_ID.equal(create + .select(AUTHOR.ID) + .from(AUTHOR) + .where(AUTHOR.LAST_NAME.equal("Orwell")))); + + +

Example: Derived table

+ + + + nested = + create.select(BOOK.AUTHOR_ID, count().as("books")) + .from(BOOK) + .groupBy(BOOK.AUTHOR_ID).asTable("nested"); + +create.select(nested.getFields()) + .from(nested) + .orderBy(nested.getField("books"));]]> + + +

Example: Correlated subquery

+ + + +Field books = + create.selectCount() + .from(BOOK) + .where(BOOK.AUTHOR_ID.equal(AUTHOR.ID)) + .asField("books"); +create.select(AUTHOR.ID, books) + .from(AUTHOR) + .orderBy(books, AUTHOR.ID));]]> + +
@@ -3374,7 +3443,33 @@ GROUP BY A, B, C WITH ROLLUP
User-defined functions - + +

User-defined functions in SQL

+

+ Some databases support user-defined functions, which can be embedded in any SQL statement, if you're using jOOQ's . Let's say you have the following simple function in Oracle SQL: +

+ + + +

+ The above function will be made available from a generated class. You can use it like any other : +

+ + + + + + +

+ Note that user-defined functions returning or data types can also be used wherever can be used, if they are +

+
@@ -4092,11 +4187,6 @@ notExists(create.selectOne().from(BOOK)

- -
- ARRAY predicates - -
@@ -4354,11 +4444,11 @@ param2.setValue("Orwell");]]> The interface also allows for setting new bind values directly, without accessing the Param type:

-

@@ -4368,13 +4458,13 @@ query2.bind("lastName", "Orwell");]]> @@ -4404,7 +4494,7 @@ WHERE LAST_NAME = :lastName]]> // single bind values to be rendered as inline values // -------------------------------------------------- create.select() - .from(T_AUTHOR) + .from(AUTHOR) .where(LAST_NAME.equal(inline("Poe"))); // Or render the whole query with inlined values @@ -4417,7 +4507,7 @@ Factory create = new Factory(connection, SQLDialect.ORACLE, settings); // Run queries that omit rendering schema names create.select() - .from(T_AUTHOR) + .from(AUTHOR) .where(LAST_NAME.equal("Poe"));]]> @@ -4539,12 +4629,12 @@ int peekIndex();]]>

An example of rendering SQL

- A simple example can be provided by checking out jOOQ's internal representation of a (simplified) . It is used for any comparing two fields as for example the T_AUTHOR.ID = T_BOOK.AUTHOR_ID condition here: + A simple example can be provided by checking out jOOQ's internal representation of a (simplified) . It is used for any comparing two fields as for example the AUTHOR.ID = BOOK.AUTHOR_ID condition here:

-- [...] -FROM T_AUTHOR -JOIN T_BOOK ON T_AUTHOR.ID = T_BOOK.AUTHOR_ID +FROM AUTHOR +JOIN BOOK ON AUTHOR.ID = BOOK.AUTHOR_ID -- [...]

@@ -4623,11 +4713,11 @@ BindContext bindValues(Object... values) throws DataAccessException;]]>

An example of binding values to SQL

- A simple example can be provided by checking out jOOQ's internal representation of a (simplified) . It is used for any comparing two fields as for example the T_AUTHOR.ID = T_BOOK.AUTHOR_ID condition here: + A simple example can be provided by checking out jOOQ's internal representation of a (simplified) . It is used for any comparing two fields as for example the AUTHOR.ID = BOOK.AUTHOR_ID condition here:

-- [...] -WHERE T_AUTHOR.ID = ? +WHERE AUTHOR.ID = ? -- [...]

@@ -5789,7 +5879,7 @@ create.insertInto(AUTHOR, AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME) If you're using jOOQ's , it will generate objects for you. Let's consider the following example:

-

@@ -5828,7 +5918,7 @@ assertEquals(new BigDecimal("2"), procedure.getId();]]> Unlike procedures, functions can be inlined in SQL statements to generate or , if you're using . Assume you have a function like this:

-

@@ -5884,7 +5974,7 @@ create.select(authorExists("Paulo")).fetchOne(0, boolean.class);]]> last_name VARCHAR2(50), MEMBER PROCEDURE LOAD, - MEMBER FUNCTION count_books RETURN NUMBER + MEMBER FUNCTION counBOOKs RETURN NUMBER ) -- The type body is omitted for the example]]> @@ -6845,8 +6935,8 @@ create.select(BOOK.ID, BOOK.TITLE).from(BOOK).orderBy(BOOK.ID).limit(1, 2).fetch The above query may result in the following log output:

- with bind values : select "T_BOOK"."ID", "T_BOOK"."TITLE" from "T_BOOK" order by "T_BOOK"."ID" asc, limit 2 offset 1 + with bind values : select "BOOK"."ID", "BOOK"."TITLE" from "BOOK" order by "BOOK"."ID" asc, limit 2 offset 1 Query executed : Total: 1.439ms Fetched result : +----+------------+ : | ID|TITLE |