From fc01c7acc998e7142fe3d6d9515d687e98ed1eaa Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Fri, 30 Jun 2017 13:37:36 +0200 Subject: [PATCH] Fix DBF handling of "empty" date strings. Blind code a fix for an error when parsing empty date strings in a DBF file. The small amount of information is surprising, I can't quite figure out which input string can produce " - - " with the previous coding of db3-date-to-pgsql-date. Anyway, it seems easy enough to add some checks to a very optimistic function and return nil when our checks aren't met. Fixes #589, hopefully. --- src/sources/db3/db3-schema.lisp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sources/db3/db3-schema.lisp b/src/sources/db3/db3-schema.lisp index ae2282b..1e99ee8 100644 --- a/src/sources/db3/db3-schema.lisp +++ b/src/sources/db3/db3-schema.lisp @@ -78,8 +78,10 @@ (defun db3-date-to-pgsql-date (value) "Convert a DB3 date to a PostgreSQL date." - (let ((year (subseq value 0 4)) - (month (subseq value 4 6)) - (day (subseq value 6 8))) - (format nil "~a-~a-~a" year month day))) + (when (and value (string/= "" value) (= 8 (length value))) + (let ((year (parse-integer (subseq value 0 4) :junk-allowed t)) + (month (parse-integer (subseq value 4 6) :junk-allowed t)) + (day (parse-integer (subseq value 6 8) :junk-allowed t))) + (when (and year month day) + (format nil "~4,'0d-~2,'0d-~2,'0d" year month day)))))