[#1595] Simulate REPEAT() in SQLite
This commit is contained in:
parent
12e6e295c6
commit
cc9d960ae1
@ -528,7 +528,6 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
|
||||
// REPEAT
|
||||
switch (getDialect()) {
|
||||
case DERBY:
|
||||
case SQLITE:
|
||||
log.info("SKIPPING", "REPEAT function");
|
||||
break;
|
||||
|
||||
|
||||
@ -2769,7 +2769,7 @@ public class Factory implements FactoryOperations {
|
||||
*
|
||||
* @see #repeat(Field, Field)
|
||||
*/
|
||||
@Support({ ASE, CUBRID, DB2, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLSERVER, SYBASE })
|
||||
@Support({ ASE, CUBRID, DB2, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
|
||||
public static Field<String> repeat(String field, int count) {
|
||||
return repeat(val(field, String.class), val(count));
|
||||
}
|
||||
@ -2779,7 +2779,7 @@ public class Factory implements FactoryOperations {
|
||||
*
|
||||
* @see #repeat(Field, Field)
|
||||
*/
|
||||
@Support({ ASE, CUBRID, DB2, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLSERVER, SYBASE })
|
||||
@Support({ ASE, CUBRID, DB2, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
|
||||
public static Field<String> repeat(String field, Field<? extends Number> count) {
|
||||
return repeat(val(field, String.class), nullSafe(count));
|
||||
}
|
||||
@ -2789,7 +2789,7 @@ public class Factory implements FactoryOperations {
|
||||
*
|
||||
* @see #repeat(Field, Field)
|
||||
*/
|
||||
@Support({ ASE, CUBRID, DB2, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLSERVER, SYBASE })
|
||||
@Support({ ASE, CUBRID, DB2, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
|
||||
public static Field<String> repeat(Field<String> field, int count) {
|
||||
return repeat(nullSafe(field), val(count));
|
||||
}
|
||||
@ -2803,8 +2803,11 @@ public class Factory implements FactoryOperations {
|
||||
* using rpad and length, which may be simulated as well, depending on the
|
||||
* RDBMS:
|
||||
* <code><pre>rpad([field], length([field]) * [count], [field])</pre></code>
|
||||
* <p>
|
||||
* In {@link SQLDialect#SQLITE}, this is simulated as such:
|
||||
* <code><pre>replace(substr(quote(zeroblob(([count] + 1) / 2)), 3, [count]), '0', [field])</pre></code>
|
||||
*/
|
||||
@Support({ ASE, CUBRID, DB2, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLSERVER, SYBASE })
|
||||
@Support({ ASE, CUBRID, DB2, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
|
||||
public static Field<String> repeat(Field<String> field, Field<? extends Number> count) {
|
||||
return new Repeat(nullSafe(field), nullSafe(count));
|
||||
}
|
||||
|
||||
@ -67,6 +67,13 @@ class Repeat extends AbstractFunction<String> {
|
||||
case ORACLE:
|
||||
return Factory.rpad(string, Factory.length(string).mul(count), string);
|
||||
|
||||
// Simulation of REPEAT() for SQLite currently cannot be achieved
|
||||
// using RPAD() above, as RPAD() expects characters, not strings
|
||||
// Another option is documented here, though:
|
||||
// http://stackoverflow.com/questions/11568496/how-to-simulate-repeat-in-sqlite
|
||||
case SQLITE:
|
||||
return Factory.field("replace(substr(quote(zeroblob(({0} + 1) / 2)), 3, {1}), '0', {2})", String.class, count, count, string);
|
||||
|
||||
case ASE:
|
||||
case SQLSERVER:
|
||||
return function("replicate", SQLDataType.VARCHAR, string, count);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user