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.
This commit is contained in:
Dimitri Fontaine 2014-01-11 18:28:24 +01:00
parent 539ad57347
commit 07c614c170
4 changed files with 26 additions and 4 deletions

View File

@ -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 ;

View File

@ -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)

View File

@ -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"

View File

@ -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'"