[jOOQ/jOOQ#13786] Parser should support TIMESTAMP 'YYYY-MM-DD' and TIME 'HH:MM' literals

This commit is contained in:
Lukas Eder 2023-09-04 17:27:27 +02:00
parent cb9ff43fcd
commit 9f588ae05f
3 changed files with 27 additions and 17 deletions

View File

@ -1614,9 +1614,10 @@ final class Convert {
}
static final String patchIso8601Time(String string) {
// [#12158] Support Db2's 15.30.45 format
return string.length() == 8
return string.length() == 5
? (string + ":00")
// [#12158] Support Db2's 15.30.45 format
: string.length() == 8
? string.replace('.', ':')
: string;
}
@ -1627,6 +1628,10 @@ final class Convert {
if (string.endsWith(" UTC"))
string = string.replace(" UTC", "Z");
// [#13786] Be lenient with PostgreSQL style abbreviated time stamp literals
if (string.length() == 10)
return string + (t ? "T" : " ") + "00:00:00";
if (string.length() > 11)
if (t && string.charAt(10) == ' ')
return string.substring(0, 10) + "T" + string.substring(11);

View File

@ -10477,12 +10477,12 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
}
private final Timestamp parseTimestampLiteral() {
try {
return Timestamp.valueOf(parseStringLiteral());
}
catch (IllegalArgumentException e) {
Timestamp timestamp = Convert.convert(parseStringLiteral(), Timestamp.class);
if (timestamp == null)
throw exception("Illegal timestamp literal");
}
return timestamp;
}
private final Field<?> parseFieldTimeLiteralIf() {
@ -10510,12 +10510,12 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
}
private final Time parseTimeLiteral() {
try {
return Time.valueOf(parseStringLiteral());
}
catch (IllegalArgumentException e) {
Time time = Convert.convert(parseStringLiteral(), Time.class);
if (time == null)
throw exception("Illegal time literal");
}
return time;
}
private final Field<?> parseFieldIntervalLiteralIf() {

View File

@ -1334,10 +1334,11 @@ public final class Convert {
: string;
}
private static final String patchIso8601Time(String string) {
// [#12158] Support Db2's 15.30.45 format
return string.length() == 8
static final String patchIso8601Time(String string) {
return string.length() == 5
? (string + ":00")
// [#12158] Support Db2's 15.30.45 format
: string.length() == 8
? string.replace('.', ':')
: string;
}
@ -1348,6 +1349,10 @@ public final class Convert {
if (string.endsWith(" UTC"))
string = string.replace(" UTC", "Z");
// [#13786] Be lenient with PostgreSQL style abbreviated time stamp literals
if (string.length() == 10)
return string + (t ? "T" : " ") + "00:00:00";
if (string.length() > 11)
if (t && string.charAt(10) == ' ')
return string.substring(0, 10) + "T" + string.substring(11);