-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalize source string when parsing #609
Conversation
The regex used to parse dates does not account for the fact that new dates created by SQLite's CURRENT_TIMESTAMP do not include millisecond information. The regex used by the date parser tries to find a string matching "yyyy-MM-dd HH:mm:ss.SSS" but the dates created by SQLite do not include the milliseconds (.SSS) so the date strings are not matching and this is causing the parser to return null. The solution is to detect this exact case (string length is exactly 19) and then append .000 to the source string. This causes the regex to match on the string. allowing the date string to be parsed, and the Date object to be returned. The source object is not mutated, and the extra characters do not change the DATETIME represented by the date string, so I think this is a safe fix.
No unit test to catch possible future regression? |
@bendem I'm a little outside my comfort zone here, but I gave it a shot. I added a unit test to the StatementTest class. Let me know what you think. |
Looks good to me, but I'm not maintainer :) |
Thanks for the fix. It looks good to me |
@davidjpfeiffer Sorry. It's once merged, but the CI is failing because of this change. Could you submit a change again? |
@xerial sure, should I create a new PR with the exact same changes? |
Yes. In another PR, GitHub Action CI will run to find any issue in advance |
This pull request fixes the bug described by issue #88
This bug can be reproduced by using
ResultSet.getDate()
to parse aDATETIME
created usingCURRENT_TIMESTAMP
The exception thrown will look something like this:
java.text.ParseException: Unparseable date: "2021-06-08 02:00:47" does not match (\p{Nd}++)\Q-\E(\p{Nd}++)\Q-\E(\p{Nd}++)\Q \E(\p{Nd}++)\Q:\E(\p{Nd}++)\Q:\E(\p{Nd}++)\Q.\E(\p{Nd}++)
The regex used to parse dates does not account for the fact that new dates created by SQLite's
CURRENT_TIMESTAMP
do not include millisecond information. The regex used by the date parser tries to find a string matchingyyyy-MM-dd HH:mm:ss.SSS
but the dates created by SQLite do not include the milliseconds.SSS
so the date strings are not matching and this is causing the parser to return null. The solution implemented in this pull request detects this exact case (string length is exactly 19) and then appends.000
to the source string. This causes the regex to match on the string allowing the date string to be parsed and the Date object to be returned. The source object is not mutated, and the extra characters do not change theDATETIME
represented by the date string, so I think this is a safe fix.Please let me know if you have any questions about this.