[#7325] Error when fetching SQLite timestamps in ISO format (including the letter T)
This commit is contained in:
parent
f22d93f52b
commit
cc6ed7f861
@ -9722,6 +9722,18 @@ from (
|
||||
The Parser API can be used as a translator between source and target dialects programmatically, as we've seen in the <reference id="sql-parser-api" title="previous section about the parser API"/>. This functionality can also usefully be accessed on the command line as shown below:
|
||||
</p>
|
||||
|
||||
</html><text><![CDATA[$ java -jar jooq-{jooq-version}.jar org.jooq.ParserCLI -h
|
||||
Usage:
|
||||
-f / --formatted Format output SQL
|
||||
-h / --help Display this help
|
||||
-k / --keyword <RenderKeywordStyle> Specify the output keyword style (org.jooq.conf.RenderKeywordStyle)
|
||||
-i / --identifier <RenderNameStyle> Specify the output identifier style (org.jooq.conf.RenderNameStyle)
|
||||
-t / --to-dialect <SQLDialect> Specify the output dialect (org.jooq.SQLDialect)
|
||||
-s / --sql <String> Specify the input SQL string
|
||||
|
||||
$ java -jar jooq-{jooq-version}.jar org.jooq.ParserCLI -t ORACLE -s "SELECT substring('abcde', 2, 3)"
|
||||
select substr('abcde', 2, 3) from dual;]]></text><html>
|
||||
|
||||
<p>
|
||||
Another way to use this API is the <a href="https://www.jooq.org/translate">https://www.jooq.org/translate</a> website.
|
||||
</p>
|
||||
|
||||
@ -41,6 +41,7 @@ import org.jooq.conf.RenderKeywordStyle;
|
||||
import org.jooq.conf.RenderNameStyle;
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.ParserException;
|
||||
|
||||
/**
|
||||
* A command line interface to the Parser API, which works in a similar way as
|
||||
@ -76,7 +77,23 @@ public final class ParserCLI {
|
||||
settings.setRenderNameStyle(a.name);
|
||||
|
||||
DSLContext ctx = DSL.using(a.toDialect, settings);
|
||||
System.out.println(ctx.render(ctx.parser().parse(a.sql)));
|
||||
try {
|
||||
System.out.println(ctx.render(ctx.parser().parse(a.sql)));
|
||||
}
|
||||
catch (ParserException e1) {
|
||||
ParserException e = e1;
|
||||
|
||||
if (!a.sql.trim().matches("^(?is:(ALTER|BEGIN|COMMENT|CREATE|DECLARE|DELETE|DESCRIBE|DROP|GRANT|INSERT|MERGE|RENAME|REVOKE|SELECT|SET|SHOW|TRUNCATE|UPDATE|USE).*)$")) {
|
||||
try {
|
||||
System.out.println(ctx.render(ctx.parser().parseField(a.sql)));
|
||||
}
|
||||
catch (ParserException e2) {
|
||||
e = e1.position() >= e2.position() ? e1 : e2;
|
||||
}
|
||||
}
|
||||
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Args parse(String[] args) {
|
||||
@ -170,7 +187,7 @@ public final class ParserCLI {
|
||||
System.out.println(" -s / --sql <String> Specify the input SQL string");
|
||||
}
|
||||
|
||||
static final class Args {
|
||||
public static final class Args {
|
||||
String sql;
|
||||
RenderKeywordStyle keywords;
|
||||
RenderNameStyle name;
|
||||
|
||||
@ -417,14 +417,18 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
|
||||
// If that fails, try reading a formatted date
|
||||
catch (NumberFormatException e) {
|
||||
|
||||
// [#7325] In SQLite dates could be stored in both ISO standard formats:
|
||||
// With T (default standard), or without T (optional standard, JDBC standard)
|
||||
date = StringUtils.replace(date, "T", " ");
|
||||
|
||||
if (type == Timestamp.class)
|
||||
return Timestamp.valueOf(date).getTime();
|
||||
|
||||
// Dates may come with " 00:00:00". This is safely trimming time information
|
||||
if (type == Date.class)
|
||||
else if (type == Date.class)
|
||||
return Date.valueOf(date.split(" ")[0]).getTime();
|
||||
|
||||
if (type == Time.class)
|
||||
else if (type == Time.class)
|
||||
return Time.valueOf(date).getTime();
|
||||
|
||||
throw new SQLException("Could not parse date " + date, e);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user