[jOOQ/jOOQ#11061] [jOOQ/jOOQ#11070] [jOOQ/jOOQ#11091] LPAD / RPAD
This commit is contained in:
parent
aecc0e5b4c
commit
574e754752
@ -14953,6 +14953,114 @@ public class DSL {
|
||||
return new Lower(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(String string, int length, String character) {
|
||||
return new Lpad(Tools.field(string), Tools.field(length), Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(String string, int length, Field<String> character) {
|
||||
return new Lpad(Tools.field(string), Tools.field(length), character);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(String string, Field<? extends Number> length, String character) {
|
||||
return new Lpad(Tools.field(string), length, Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(String string, Field<? extends Number> length, Field<String> character) {
|
||||
return new Lpad(Tools.field(string), length, character);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> string, int length, String character) {
|
||||
return new Lpad(string, Tools.field(length), Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> string, int length, Field<String> character) {
|
||||
return new Lpad(string, Tools.field(length), character);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> string, Field<? extends Number> length, String character) {
|
||||
return new Lpad(string, length, Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> string, Field<? extends Number> length, Field<String> character) {
|
||||
return new Lpad(string, length, character);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(String string, int length) {
|
||||
return new Lpad(Tools.field(string), Tools.field(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(String string, Field<? extends Number> length) {
|
||||
return new Lpad(Tools.field(string), length);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> string, int length) {
|
||||
return new Lpad(string, Tools.field(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> string, Field<? extends Number> length) {
|
||||
return new Lpad(string, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LTRIM</code> function.
|
||||
*/
|
||||
@ -15313,6 +15421,114 @@ public class DSL {
|
||||
return new Right(string, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(String string, int length, String character) {
|
||||
return new Rpad(Tools.field(string), Tools.field(length), Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(String string, int length, Field<String> character) {
|
||||
return new Rpad(Tools.field(string), Tools.field(length), character);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(String string, Field<? extends Number> length, String character) {
|
||||
return new Rpad(Tools.field(string), length, Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(String string, Field<? extends Number> length, Field<String> character) {
|
||||
return new Rpad(Tools.field(string), length, character);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> string, int length, String character) {
|
||||
return new Rpad(string, Tools.field(length), Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> string, int length, Field<String> character) {
|
||||
return new Rpad(string, Tools.field(length), character);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> string, Field<? extends Number> length, String character) {
|
||||
return new Rpad(string, length, Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> string, Field<? extends Number> length, Field<String> character) {
|
||||
return new Rpad(string, length, character);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(String string, int length) {
|
||||
return new Rpad(Tools.field(string), Tools.field(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(String string, Field<? extends Number> length) {
|
||||
return new Rpad(Tools.field(string), length);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> string, int length) {
|
||||
return new Rpad(string, Tools.field(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RPAD</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> string, Field<? extends Number> length) {
|
||||
return new Rpad(string, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>RTRIM</code> function.
|
||||
*/
|
||||
@ -15579,32 +15795,6 @@ public class DSL {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the rpad(field, length) function.
|
||||
*
|
||||
* @see #rpad(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> field, int length) {
|
||||
return rpad(Tools.nullSafe(field), Tools.field(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rpad(field, length) function.
|
||||
* <p>
|
||||
* This renders the rpad function where available:
|
||||
* <code><pre>rpad([field], [length])</pre></code> ... or emulates it
|
||||
* elsewhere using concat, repeat, and length, which may be emulated as
|
||||
* well, depending on the RDBMS:
|
||||
* <code><pre>concat([field], repeat(' ', [length] - length([field])))</pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> field, Field<? extends Number> length) {
|
||||
return new Rpad(Tools.nullSafe(field), Tools.nullSafe(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rpad(field, length, character) function.
|
||||
*
|
||||
@ -15616,61 +15806,6 @@ public class DSL {
|
||||
return rpad(field, length, Character.toString(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rpad(field, length, character) function.
|
||||
*
|
||||
* @see #rpad(Field, Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> field, int length, String character) {
|
||||
return rpad(Tools.nullSafe(field), Tools.field(length), Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rpad(field, length, character) function.
|
||||
* <p>
|
||||
* This renders the rpad function where available:
|
||||
* <code><pre>rpad([field], [length])</pre></code> ... or emulates it
|
||||
* elsewhere using concat, repeat, and length, which may be emulated as
|
||||
* well, depending on the RDBMS:
|
||||
* <code><pre>concat([field], repeat([character], [length] - length([field])))</pre></code>
|
||||
* <p>
|
||||
* In {@link SQLDialect#SQLITE}, this is emulated as such:
|
||||
* <code><pre>[field] || replace(replace(substr(quote(zeroblob(([length] + 1) / 2)), 3, ([length] - length([field]))), '\''', ''), '0', [character])</pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> rpad(Field<String> field, Field<? extends Number> length, Field<String> character) {
|
||||
return new Rpad(Tools.nullSafe(field), Tools.nullSafe(length), Tools.nullSafe(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lpad(field, length) function.
|
||||
*
|
||||
* @see #lpad(Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> field, int length) {
|
||||
return lpad(Tools.nullSafe(field), Tools.field(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lpad(field, length) function.
|
||||
* <p>
|
||||
* This renders the lpad function where available:
|
||||
* <code><pre>lpad([field], [length])</pre></code> ... or emulates it
|
||||
* elsewhere using concat, repeat, and length, which may be emulated as
|
||||
* well, depending on the RDBMS:
|
||||
* <code><pre>concat(repeat(' ', [length] - length([field])), [field])</pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> field, Field<? extends Number> length) {
|
||||
return new Lpad(Tools.nullSafe(field), Tools.nullSafe(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lpad(field, length, character) function.
|
||||
*
|
||||
@ -15682,35 +15817,6 @@ public class DSL {
|
||||
return lpad(field, length, Character.toString(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lpad(field, length, character) function.
|
||||
*
|
||||
* @see #lpad(Field, Field, Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> field, int length, String character) {
|
||||
return lpad(Tools.nullSafe(field), Tools.field(length), Tools.field(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lpad(field, length, character) function.
|
||||
* <p>
|
||||
* This renders the lpad function where available:
|
||||
* <code><pre>lpad([field], [length])</pre></code> ... or emulates it
|
||||
* elsewhere using concat, repeat, and length, which may be emulated as
|
||||
* well, depending on the RDBMS:
|
||||
* <code><pre>concat(repeat([character], [length] - length([field])), [field])</pre></code>
|
||||
* <p>
|
||||
* In {@link SQLDialect#SQLITE}, this is emulated as such:
|
||||
* <code><pre>replace(replace(substr(quote(zeroblob(([length] + 1) / 2)), 3, ([length] - length([field]))), '\''', ''), '0', [character]) || [field]</pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<String> lpad(Field<String> field, Field<? extends Number> length, Field<String> character) {
|
||||
return new Lpad(Tools.nullSafe(field), Tools.nullSafe(length), Tools.nullSafe(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translate(field, from, to) function.
|
||||
*
|
||||
|
||||
@ -37,45 +37,66 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.Internal.isub;
|
||||
import static org.jooq.impl.Names.N_HEX;
|
||||
import static org.jooq.impl.Names.N_LEN;
|
||||
import static org.jooq.impl.Names.N_LENGTH;
|
||||
import static org.jooq.impl.Names.N_LPAD;
|
||||
import static org.jooq.impl.Names.N_REPLACE;
|
||||
import static org.jooq.impl.Names.N_SPACE;
|
||||
import static org.jooq.impl.Names.N_SUBSTR;
|
||||
import static org.jooq.impl.Names.N_ZEROBLOB;
|
||||
import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
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>LPAD</code> statement.
|
||||
*/
|
||||
final class Lpad extends AbstractField<String> {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class Lpad
|
||||
extends
|
||||
AbstractField<String>
|
||||
{
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -7273879239726265322L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Field<String> field;
|
||||
private final Field<String> string;
|
||||
private final Field<? extends Number> length;
|
||||
private final Field<String> character;
|
||||
|
||||
Lpad(Field<String> field, Field<? extends Number> length) {
|
||||
this(field, length, null);
|
||||
Lpad(
|
||||
Field string,
|
||||
Field length
|
||||
) {
|
||||
super(N_LPAD, allNotNull(VARCHAR, string, length));
|
||||
|
||||
this.string = nullSafeNotNull(string, VARCHAR);
|
||||
this.length = nullSafeNotNull(length, INTEGER);
|
||||
this.character = null;
|
||||
}
|
||||
|
||||
Lpad(Field<String> field, Field<? extends Number> length, Field<String> character) {
|
||||
super(N_LPAD, VARCHAR);
|
||||
Lpad(
|
||||
Field string,
|
||||
Field length,
|
||||
Field character
|
||||
) {
|
||||
super(N_LPAD, allNotNull(VARCHAR, string, length, character));
|
||||
|
||||
this.field = field;
|
||||
this.length = length;
|
||||
this.character = (character == null ? inline(" ") : character);
|
||||
this.string = nullSafeNotNull(string, VARCHAR);
|
||||
this.length = nullSafeNotNull(length, INTEGER);
|
||||
this.character = nullSafeNotNull(character, VARCHAR);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
private final Field<String> character() {
|
||||
return character == null ? inline(" ") : character;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,14 +123,16 @@ final class Lpad extends AbstractField<String> {
|
||||
.visit(N_HEX).sql('(')
|
||||
.visit(N_ZEROBLOB).sql('(')
|
||||
.visit(length)
|
||||
.sql(")), '00', ").visit(character)
|
||||
.sql("), 1, ").visit(length).sql(" - ").visit(N_LENGTH).sql('(').visit(field)
|
||||
.sql(")) || ").visit(field);
|
||||
.sql(")), '00', ").visit(character())
|
||||
.sql("), 1, ").visit(length).sql(" - ").visit(N_LENGTH).sql('(').visit(string)
|
||||
.sql(")) || ").visit(string);
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(N_LPAD).sql('(').visit(field).sql(", ").visit(length).sql(", ").visit(character).sql(')');
|
||||
ctx.visit(N_LPAD).sql('(').visit(string).sql(", ").visit(length).sql(", ").visit(character()).sql(')');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -37,45 +37,66 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.Internal.isub;
|
||||
import static org.jooq.impl.Names.N_HEX;
|
||||
import static org.jooq.impl.Names.N_LEN;
|
||||
import static org.jooq.impl.Names.N_LENGTH;
|
||||
import static org.jooq.impl.Names.N_REPLACE;
|
||||
import static org.jooq.impl.Names.N_RPAD;
|
||||
import static org.jooq.impl.Names.N_SPACE;
|
||||
import static org.jooq.impl.Names.N_SUBSTR;
|
||||
import static org.jooq.impl.Names.N_ZEROBLOB;
|
||||
import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
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>RPAD</code> statement.
|
||||
*/
|
||||
final class Rpad extends AbstractField<String> {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class Rpad
|
||||
extends
|
||||
AbstractField<String>
|
||||
{
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -7273879239726265322L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Field<String> field;
|
||||
private final Field<String> string;
|
||||
private final Field<? extends Number> length;
|
||||
private final Field<String> character;
|
||||
|
||||
Rpad(Field<String> field, Field<? extends Number> length) {
|
||||
this(field, length, null);
|
||||
Rpad(
|
||||
Field string,
|
||||
Field length
|
||||
) {
|
||||
super(N_RPAD, allNotNull(VARCHAR, string, length));
|
||||
|
||||
this.string = nullSafeNotNull(string, VARCHAR);
|
||||
this.length = nullSafeNotNull(length, INTEGER);
|
||||
this.character = null;
|
||||
}
|
||||
|
||||
Rpad(Field<String> field, Field<? extends Number> length, Field<String> character) {
|
||||
super(N_RPAD, VARCHAR);
|
||||
Rpad(
|
||||
Field string,
|
||||
Field length,
|
||||
Field character
|
||||
) {
|
||||
super(N_RPAD, allNotNull(VARCHAR, string, length, character));
|
||||
|
||||
this.field = field;
|
||||
this.length = length;
|
||||
this.character = (character == null ? inline(" ") : character);
|
||||
this.string = nullSafeNotNull(string, VARCHAR);
|
||||
this.length = nullSafeNotNull(length, INTEGER);
|
||||
this.character = nullSafeNotNull(character, VARCHAR);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
private final Field<String> character() {
|
||||
return character == null ? inline(" ") : character;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -97,19 +118,21 @@ final class Rpad extends AbstractField<String> {
|
||||
// This beautiful expression was contributed by "Ludo", here:
|
||||
// http://stackoverflow.com/questions/6576343/how-to-simulate-lpad-rpad-with-sqlite
|
||||
case SQLITE:
|
||||
ctx.visit(field).sql(" || ").visit(N_SUBSTR).sql('(')
|
||||
ctx.visit(string).sql(" || ").visit(N_SUBSTR).sql('(')
|
||||
.visit(N_REPLACE).sql('(')
|
||||
.visit(N_HEX).sql('(')
|
||||
.visit(N_ZEROBLOB).sql('(')
|
||||
.visit(length)
|
||||
.sql(")), '00', ").visit(character)
|
||||
.sql("), 1, ").visit(length).sql(" - ").visit(N_LENGTH).sql('(').visit(field).sql(')')
|
||||
.sql(")), '00', ").visit(character())
|
||||
.sql("), 1, ").visit(length).sql(" - ").visit(N_LENGTH).sql('(').visit(string).sql(')')
|
||||
.sql(')');
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(N_RPAD).sql('(').visit(field).sql(", ").visit(length).sql(", ").visit(character).sql(')');
|
||||
ctx.visit(N_RPAD).sql('(').visit(string).sql(", ").visit(length).sql(", ").visit(character()).sql(')');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user