[#7757] Improve SQLite LPAD() and RPAD() emulation

This commit is contained in:
Lukas Eder 2018-08-13 13:18:41 +02:00
parent e852dc5ba0
commit 4b95a83e27
2 changed files with 2 additions and 22 deletions

View File

@ -89,17 +89,7 @@ final class Lpad extends AbstractFunction<String> {
// http://stackoverflow.com/questions/6576343/how-to-simulate-lpad-rpad-with-sqlite
case SQLITE: {
return DSL.field(
"substr(" +
"replace(" +
"replace(" +
"substr(" +
"quote(" +
"zeroblob((({1} - length({0}) - 1 + length({2})) / length({2}) + 1) / 2)" +
"), 3" +
"), '\''', ''" +
"), '0', {2}" +
"), 1, ({1} - length({0}))" +
") || {0}",
"substr(replace(hex(zeroblob({1})), '00', {2}), 1, {1} - length({0})) || {0}",
String.class,
field, length, character);
}

View File

@ -87,17 +87,7 @@ final class Rpad extends AbstractFunction<String> {
// http://stackoverflow.com/questions/6576343/how-to-simulate-lpad-rpad-with-sqlite
case SQLITE:
return DSL.field(
"{0} || substr(" +
"replace(" +
"replace(" +
"substr(" +
"quote(" +
"zeroblob((({1} - length({0}) - 1 + length({2})) / length({2}) + 1) / 2)" +
"), 3" +
"), '\''', ''" +
"), '0', {2}" +
"), 1, ({1} - length({0}))" +
")",
"{0} || substr(replace(hex(zeroblob({1})), '00', {2}), 1, {1} - length({0}))",
String.class,
field, length, character);