Skip to content

Commit

Permalink
Switch to the newer cl-csv API.
Browse files Browse the repository at this point in the history
Thanks to the work at AccelerationNet/cl-csv#12 we
can now use the main branch of cl-csv again.
  • Loading branch information
dimitri committed Jan 11, 2014
1 parent 539ad57 commit 07c614c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
6 changes: 4 additions & 2 deletions src/sources/csv.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 20 additions & 0 deletions test/csv-trim-extra-blanks.load
Original file line number Diff line number Diff line change
@@ -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'"

0 comments on commit 07c614c

Please sign in to comment.