Including CHAR_LENGTH, BIT_LENGTH, OCTET_LENGTH
This commit is contained in:
Lukas Eder 2020-12-08 22:40:23 +01:00
parent 93c58aa9f5
commit c2805f964f
5 changed files with 281 additions and 227 deletions

View File

@ -37,34 +37,47 @@
*/
package org.jooq.impl;
import static org.jooq.impl.Names.N_ASC;
import static org.jooq.impl.Names.N_ASCII;
import static org.jooq.impl.Names.N_ASCII_VAL;
import static org.jooq.impl.SQLDataType.INTEGER;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.impl.Tools.nullSafeNotNull;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.*;
import org.jooq.impl.*;
import java.util.*;
/**
* @author Lukas Eder
* The <code>ASCII</code> statement.
*/
final class Ascii extends AbstractField<Integer> {
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
final class Ascii
extends
AbstractField<Integer>
{
/**
* Generated UID
*/
private static final long serialVersionUID = -7273879239726265322L;
private static final long serialVersionUID = 1L;
private final Field<?> string;
private final Field<String> string;
Ascii(Field<?> string) {
super(N_ASCII, INTEGER.nullable(string == null || string.getDataType().nullable()));
Ascii(
Field<String> string
) {
super(N_ASCII, allNotNull(INTEGER, string));
this.string = nullSafeNotNull(string, VARCHAR);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
@ -89,4 +102,6 @@ final class Ascii extends AbstractField<Integer> {
break;
}
}
}

View File

@ -37,39 +37,47 @@
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.function;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.Names.N_BIT_LENGTH;
import static org.jooq.impl.Names.N_CHAR_LENGTH;
import static org.jooq.impl.Names.N_DATALENGTH;
import static org.jooq.impl.Names.N_LEN;
import static org.jooq.impl.Names.N_LENGTH;
import static org.jooq.impl.Names.N_LENGTHB;
import static org.jooq.impl.SQLDataType.INTEGER;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.impl.Tools.nullSafeNotNull;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.*;
import org.jooq.impl.*;
import java.util.*;
/**
* @author Lukas Eder
* The <code>BIT LENGTH</code> statement.
*/
final class BitLength extends AbstractField<Integer> {
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
final class BitLength
extends
AbstractField<Integer>
{
/**
* Generated UID
*/
private static final long serialVersionUID = 1484652553287331042L;
private static final long serialVersionUID = 1L;
private final Field<String> field;
private final Field<String> string;
BitLength(Field<String> field) {
super(N_BIT_LENGTH, INTEGER.nullable(field == null || field.getDataType().nullable()));
BitLength(
Field<String> string
) {
super(N_BIT_LENGTH, allNotNull(INTEGER, string));
this.field = nullSafeNotNull(field, VARCHAR);
this.string = nullSafeNotNull(string, VARCHAR);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public void accept(Context<?> ctx) {
switch (ctx.family()) {
@ -97,12 +105,14 @@ final class BitLength extends AbstractField<Integer> {
case DERBY:
case SQLITE:
ctx.visit(inline(8).times(function(N_LENGTH, getDataType(), field)));
ctx.visit(inline(8).times(function(N_LENGTH, getDataType(), string)));
break;
default:
ctx.visit(function(N_BIT_LENGTH, getDataType(), field));
ctx.visit(function(N_BIT_LENGTH, getDataType(), string));
break;
}
}
}

View File

@ -37,36 +37,47 @@
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.function;
import static org.jooq.impl.Names.N_BIT_LENGTH;
import static org.jooq.impl.Names.N_CHAR_LENGTH;
import static org.jooq.impl.Names.N_LEN;
import static org.jooq.impl.Names.N_LENGTH;
import static org.jooq.impl.SQLDataType.INTEGER;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.impl.Tools.nullSafeNotNull;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.*;
import org.jooq.impl.*;
import java.util.*;
/**
* @author Lukas Eder
* The <code>CHAR LENGTH</code> statement.
*/
final class CharLength extends AbstractField<Integer> {
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
final class CharLength
extends
AbstractField<Integer>
{
/**
* Generated UID
*/
private static final long serialVersionUID = 1484652553287331042L;
private static final long serialVersionUID = 1L;
private final Field<String> field;
private final Field<String> string;
CharLength(Field<String> field) {
super(N_CHAR_LENGTH, INTEGER.nullable(field == null || field.getDataType().nullable()));
CharLength(
Field<String> string
) {
super(N_CHAR_LENGTH, allNotNull(INTEGER, string));
this.field = nullSafeNotNull(field, VARCHAR);
this.string = nullSafeNotNull(string, VARCHAR);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public void accept(Context<?> ctx) {
switch (ctx.family()) {
@ -86,12 +97,14 @@ final class CharLength extends AbstractField<Integer> {
case DERBY:
case SQLITE:
ctx.visit(function(N_LENGTH, getDataType(), field));
ctx.visit(function(N_LENGTH, getDataType(), string));
break;
default:
ctx.visit(function(N_CHAR_LENGTH, getDataType(), field));
ctx.visit(function(N_CHAR_LENGTH, getDataType(), string));
break;
}
}
}

View File

@ -14899,6 +14899,60 @@ public class DSL {
return new Abs(number);
}
/**
* The <code>ASCII</code> function.
*/
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> ascii(String string) {
return new Ascii(Tools.field(string));
}
/**
* The <code>ASCII</code> function.
*/
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> ascii(Field<String> string) {
return new Ascii(string);
}
/**
* The <code>BIT_LENGTH</code> function.
*/
@NotNull
@Support
public static Field<Integer> bitLength(String string) {
return new BitLength(Tools.field(string));
}
/**
* The <code>BIT_LENGTH</code> function.
*/
@NotNull
@Support
public static Field<Integer> bitLength(Field<String> string) {
return new BitLength(string);
}
/**
* The <code>CHAR_LENGTH</code> function.
*/
@NotNull
@Support
public static Field<Integer> charLength(String string) {
return new CharLength(Tools.field(string));
}
/**
* The <code>CHAR_LENGTH</code> function.
*/
@NotNull
@Support
public static Field<Integer> charLength(Field<String> string) {
return new CharLength(string);
}
/**
* The <code>LEFT</code> function.
*/
@ -14935,6 +14989,24 @@ public class DSL {
return new Left(string, length);
}
/**
* The <code>LENGTH</code> function, an alias for the <code>CHAR_LENGTH</code> function.
*/
@NotNull
@Support
public static Field<Integer> length(String string) {
return charLength(Tools.field(string));
}
/**
* The <code>LENGTH</code> function, an alias for the <code>CHAR_LENGTH</code> function.
*/
@NotNull
@Support
public static Field<Integer> length(Field<String> string) {
return charLength(string);
}
/**
* The <code>LOWER</code> function.
*/
@ -15061,6 +15133,78 @@ public class DSL {
return new Ltrim(string);
}
/**
* The <code>MID</code> function, an alias for the <code>SUBSTRING</code> function.
*/
@NotNull
@Support
public static Field<String> mid(Field<String> string, int startingPosition, int length) {
return substring(string, Tools.field(startingPosition), Tools.field(length));
}
/**
* The <code>MID</code> function, an alias for the <code>SUBSTRING</code> function.
*/
@NotNull
@Support
public static Field<String> mid(Field<String> string, int startingPosition, Field<? extends Number> length) {
return substring(string, Tools.field(startingPosition), length);
}
/**
* The <code>MID</code> function, an alias for the <code>SUBSTRING</code> function.
*/
@NotNull
@Support
public static Field<String> mid(Field<String> string, Field<? extends Number> startingPosition, int length) {
return substring(string, startingPosition, Tools.field(length));
}
/**
* The <code>MID</code> function, an alias for the <code>SUBSTRING</code> function.
*/
@NotNull
@Support
public static Field<String> mid(Field<String> string, Field<? extends Number> startingPosition, Field<? extends Number> length) {
return substring(string, startingPosition, length);
}
/**
* The <code>MID</code> function, an alias for the <code>SUBSTRING</code> function.
*/
@NotNull
@Support
public static Field<String> mid(Field<String> string, int startingPosition) {
return substring(string, Tools.field(startingPosition));
}
/**
* The <code>MID</code> function, an alias for the <code>SUBSTRING</code> function.
*/
@NotNull
@Support
public static Field<String> mid(Field<String> string, Field<? extends Number> startingPosition) {
return substring(string, startingPosition);
}
/**
* The <code>OCTET_LENGTH</code> function.
*/
@NotNull
@Support
public static Field<Integer> octetLength(String string) {
return new OctetLength(Tools.field(string));
}
/**
* The <code>OCTET_LENGTH</code> function.
*/
@NotNull
@Support
public static Field<Integer> octetLength(Field<String> string) {
return new OctetLength(string);
}
/**
* The <code>POSITION</code> function.
*/
@ -15823,29 +15967,6 @@ public class DSL {
return overlay(in, placing, startIndex, length);
}
/**
* Get the ascii(field) function.
*
* @see #ascii(Field)
*/
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> ascii(String field) {
return ascii(Tools.field(field));
}
/**
* Get the ascii(field) function.
* <p>
* This renders the ascii function:
* <code><pre>ascii([field])</pre></code>
*/
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> ascii(Field<String> field) {
return new Ascii(field);
}
/**
* Get the <code>concat(field, value)</code> function.
*
@ -15895,120 +16016,6 @@ public class DSL {
return new Concat(Tools.nullSafe(fields));
}
/**
* Get the mid(field, startingPosition, length) function.
*
* @see #substring(Field, Field, Field)
*/
@NotNull
@Support
public static Field<String> mid(Field<String> field, int startingPosition, int length) {
return substring(field, Tools.field(startingPosition), Tools.field(length));
}
/**
* Get the mid(field, startingPosition, length) function.
* <p>
* This renders the substr or substring function:
* <code><pre>substr([field], [startingPosition], [length]) or
* substring([field], [startingPosition], [length])</pre></code>
*/
@NotNull
@Support
public static Field<String> mid(Field<String> field, Field<? extends Number> startingPosition, Field<? extends Number> length) {
return substring(field, startingPosition, length);
}
/**
* Get the length of a <code>VARCHAR</code> type. This is a synonym for
* {@link #charLength(String)}.
*
* @see #charLength(String)
*/
@NotNull
@Support
public static Field<Integer> length(String value) {
return length(Tools.field(value));
}
/**
* Get the length of a <code>VARCHAR</code> type. This is a synonym for
* {@link #charLength(Field)}.
*
* @see #charLength(Field)
*/
@NotNull
@Support
public static Field<Integer> length(Field<String> field) {
return charLength(field);
}
/**
* Get the char_length(field) function.
* <p>
* This translates into any dialect
*/
@NotNull
@Support
public static Field<Integer> charLength(String value) {
return charLength(Tools.field(value));
}
/**
* Get the char_length(field) function.
* <p>
* This translates into any dialect
*/
@NotNull
@Support
public static Field<Integer> charLength(Field<String> field) {
return new CharLength(field);
}
/**
* Get the bit_length(field) function.
* <p>
* This translates into any dialect
*/
@NotNull
@Support
public static Field<Integer> bitLength(String value) {
return bitLength(Tools.field(value));
}
/**
* Get the bit_length(field) function.
* <p>
* This translates into any dialect
*/
@NotNull
@Support
public static Field<Integer> bitLength(Field<String> field) {
return new BitLength(field);
}
/**
* Get the octet_length(field) function.
* <p>
* This translates into any dialect
*/
@NotNull
@Support
public static Field<Integer> octetLength(String value) {
return octetLength(Tools.field(value));
}
/**
* Get the octet_length(field) function.
* <p>
* This translates into any dialect
*/
@NotNull
@Support
public static Field<Integer> octetLength(Field<String> field) {
return new OctetLength(field);
}
// ------------------------------------------------------------------------
// XXX Hash function factory
// ------------------------------------------------------------------------

View File

@ -37,40 +37,47 @@
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.function;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.Names.N_BIT_LENGTH;
import static org.jooq.impl.Names.N_CHAR_LENGTH;
import static org.jooq.impl.Names.N_DATALENGTH;
import static org.jooq.impl.Names.N_LEN;
import static org.jooq.impl.Names.N_LENGTH;
import static org.jooq.impl.Names.N_LENGTHB;
import static org.jooq.impl.Names.N_OCTET_LENGTH;
import static org.jooq.impl.SQLDataType.INTEGER;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.impl.Tools.nullSafeNotNull;
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.*;
import org.jooq.impl.*;
import java.util.*;
/**
* @author Lukas Eder
* The <code>OCTET LENGTH</code> statement.
*/
final class OctetLength extends AbstractField<Integer> {
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
final class OctetLength
extends
AbstractField<Integer>
{
/**
* Generated UID
*/
private static final long serialVersionUID = 1484652553287331042L;
private static final long serialVersionUID = 1L;
private final Field<String> field;
private final Field<String> string;
OctetLength(Field<String> field) {
super(N_BIT_LENGTH, INTEGER.nullable(field == null || field.getDataType().nullable()));
OctetLength(
Field<String> string
) {
super(N_OCTET_LENGTH, allNotNull(INTEGER, string));
this.field = nullSafeNotNull(field, VARCHAR);
this.string = nullSafeNotNull(string, VARCHAR);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public void accept(Context<?> ctx) {
switch (ctx.family()) {
@ -93,12 +100,14 @@ final class OctetLength extends AbstractField<Integer> {
case DERBY:
case SQLITE:
ctx.visit(function(N_LENGTH, getDataType(), field));
ctx.visit(function(N_LENGTH, getDataType(), string));
break;
default:
ctx.visit(function(N_OCTET_LENGTH, getDataType(), field));
ctx.visit(function(N_OCTET_LENGTH, getDataType(), string));
break;
}
}
}