From 07c614c170baec0960ced83a5ab95f34974b6f39 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sat, 11 Jan 2014 18:28:24 +0100 Subject: [PATCH] Switch to the newer cl-csv API. Thanks to the work at https://github.com/AccelerationNet/cl-csv/pull/12 we can now use the main branch of cl-csv again. --- Makefile | 2 +- src/sources/csv.lisp | 6 ++++-- ...s-null.load => csv-keep-extra-blanks.load} | 2 +- test/csv-trim-extra-blanks.load | 20 +++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) rename test/{csv-empty-as-null.load => csv-keep-extra-blanks.load} (90%) create mode 100644 test/csv-trim-extra-blanks.load diff --git a/Makefile b/Makefile index 71b0ccff..715d2240 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ docs: git clone https://github.com/qitab/qmynd.git $@ ~/quicklisp/local-projects/cl-csv: - git clone -b empty-strings-and-nil https://github.com/dimitri/cl-csv.git $@ + git clone https://github.com/AccelerationNet/cl-csv.git $@ postmodern: ~/quicklisp/local-projects/Postmodern ; qmynd: ~/quicklisp/local-projects/qmynd ; diff --git a/src/sources/csv.lisp b/src/sources/csv.lisp index 3ad27e06..93aca49a 100644 --- a/src/sources/csv.lisp +++ b/src/sources/csv.lisp @@ -26,7 +26,7 @@ :initform cl-csv:*quote-escape*) (trim-blanks :accessor csv-trim-blanks ; CSV blank and NULLs :initarg :trim-blanks ; - :initform cl-csv:*trim-blanks*)) + :initform t)) (:documentation "pgloader CSV Data Source")) (defmethod initialize-instance :after ((csv copy-csv) &key) @@ -98,7 +98,9 @@ :separator (csv-separator csv) :quote (csv-quote csv) :escape (csv-escape csv) - :trim-blanks (csv-trim-blanks csv)) + :unquoted-empty-string-is-nil t + :quoted-empty-string-is-nil nil + :trim-outer-whitespace (csv-trim-blanks csv)) ((or cl-csv:csv-parse-error type-error) (condition) (progn (log-message :error "~a" condition) diff --git a/test/csv-empty-as-null.load b/test/csv-keep-extra-blanks.load similarity index 90% rename from test/csv-empty-as-null.load rename to test/csv-keep-extra-blanks.load index 20989469..cb2e2058 100644 --- a/test/csv-empty-as-null.load +++ b/test/csv-keep-extra-blanks.load @@ -17,4 +17,4 @@ LOAD CSV "unquoted blanks", ,"should be null" "unquoted string",no quote,"should be 'no quote'" "quoted separator","a,b,c","should be 'a,b,c'" -"keep extra blanks", test string , "should be ' test string '" +"keep extra blanks", test string , "should be an error" diff --git a/test/csv-trim-extra-blanks.load b/test/csv-trim-extra-blanks.load new file mode 100644 index 00000000..fc570819 --- /dev/null +++ b/test/csv-trim-extra-blanks.load @@ -0,0 +1,20 @@ +LOAD CSV + FROM INLINE + INTO postgresql:///pgloader?nulls (f1, f2, f3) + WITH truncate, + trim unquoted blanks, + fields optionally enclosed by '"', + fields escaped by double-quote, + fields terminated by ',' + + BEFORE LOAD DO + $$ drop table if exists nulls; $$, + $$ create table if not exists nulls (id serial, f1 text, f2 text, f3 text); $$; + +"quoted empty string","","should be empty string" +"no value between separators",,"should be null" +"quoted blanks"," ","should be blanks" +"unquoted blanks", ,"should be null" +"unquoted string",no quote,"should be 'no quote'" +"quoted separator","a,b,c","should be 'a,b,c'" +"trim extra blanks", test string , "should be 'test string'"