All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jooq.SQL Maven / Gradle / Ivy

There is a newer version: 3.19.15
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Other licenses:
 * -----------------------------------------------------------------------------
 * Commercial licenses for this work are available. These replace the above
 * Apache-2.0 and offer limited warranties, support, maintenance, and commercial
 * database integrations.
 *
 * For more information, please visit: https://www.jooq.org/legal/licensing
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
package org.jooq;

import org.jooq.conf.ParamType;
import org.jooq.conf.StatementType;
import org.jooq.impl.DSL;

/**
 * A plain SQL {@link QueryPart}.
 * 

* Plain SQL query parts can be constructed in a variety of ways from the * {@link DSL} API ({@link DSL#field(String)}, {@link DSL#table(String)}, etc.) * as well as from convenience methods such as for instance * {@link SelectWhereStep#where(String)}. These query parts allow for embedding * simple SQL strings with associated bind variables or nested queryparts. *

*

Template language

*

* A simple template language is implemented by such plain SQL query parts, * exposing the following features: *

    *
  • Nested query parts: A template may refer to argument * query parts using zero-based, numbered references wrapped in curly braces. * The following expression will embed expr1 and expr2 * at the appropriate locations: *

    *

    
     * DSL.field("GROUP_CONCAT(DISTINCT {0} ORDER BY {1} ASC SEPARATOR '-')", expr1, expr2);
     * 
    Query part indexes may be referenced multiple times from within * a template.
  • *
  • Keywords: Curly braces are also used to delimit * keywords, which expose the behaviour specified in {@link DSL#keyword(String)} * (e.g. upper-casing, lower-casing, etc.) . The following expression makes use * of embedded keywords in a plain SQL template: *

    *

    DSL.field("{current_timestamp}");
  • *
  • JDBC escape syntax: JDBC also allows for using curly * braces to embed escape expressions in SQL statements, such as date literals, * for instance. JDBC escape syntax is left untouched by jOOQ's plain SQL query * part renderings. The following example shows such usage: *

    *

    DSL.field("{d '2015-01-01'}");
    The following JDBC * escape syntax elements are recognised: *
      *
    • {d [date literal]}
    • *
    • {t [time literal]}
    • *
    • {ts [timestamp literal]}
    • *
    • {fn [function literal]}
    • *
    *
  • *
  • JDBC bind variables: in case bind variables should be * inlined (as in {@link DSL#inline(CharSequence)}, {@link ParamType#INLINED}, * or {@link StatementType#STATIC_STATEMENT}), plain SQL query parts will * discover question marks (?) and named parameters * (:identifier) at syntactically appropriate positions, e.g. * outside of comments, string literals, quoted name literals, and substitute * the appropriate bind value into the template.
  • *
*

* Instances can be created using {@link DSL#sql(String)} and overloads. * * @author Lukas Eder */ @PlainSQL public interface SQL extends QueryPart { }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy