|
57 | 57 | ;;;
|
58 | 58 | ;;; Read a file format in CSV format, and call given function on each line.
|
59 | 59 | ;;;
|
60 |
| -(defmethod parse-header ((csv copy-csv) header) |
| 60 | +(defmethod parse-header ((csv copy-csv)) |
61 | 61 | "Parse the header line given csv setup."
|
62 | 62 | ;; a field entry is a list of field name and options
|
63 |
| - (mapcar #'list |
64 |
| - (car ; parsing a single line |
65 |
| - (cl-csv:read-csv header |
66 |
| - :separator (csv-separator csv) |
67 |
| - :quote (csv-quote csv) |
68 |
| - :escape (csv-escape csv) |
69 |
| - :unquoted-empty-string-is-nil t |
70 |
| - :quoted-empty-string-is-nil nil |
71 |
| - :trim-outer-whitespace (csv-trim-blanks csv) |
72 |
| - :newline (csv-newline csv))))) |
| 63 | + (with-connection (cnx (source csv) |
| 64 | + :direction :input |
| 65 | + :external-format (encoding csv) |
| 66 | + :if-does-not-exist nil) |
| 67 | + (let ((input (md-strm cnx))) |
| 68 | + (loop :repeat (skip-lines csv) :do (read-line input nil nil)) |
| 69 | + (let* ((header-line (read-line input nil nil)) |
| 70 | + (field-name-list |
| 71 | + (mapcar #'list ; we need each field to be a list |
| 72 | + (car ; parsing a single line |
| 73 | + (cl-csv:read-csv header-line |
| 74 | + :separator (csv-separator csv) |
| 75 | + :quote (csv-quote csv) |
| 76 | + :escape (csv-escape csv) |
| 77 | + :unquoted-empty-string-is-nil t |
| 78 | + :quoted-empty-string-is-nil nil |
| 79 | + :trim-outer-whitespace (csv-trim-blanks csv) |
| 80 | + :newline (csv-newline csv)))))) |
| 81 | + (log-message :notice "Parsed header columns ~s" (fields csv)) |
| 82 | + (setf (fields csv) field-name-list ))))) |
73 | 83 |
|
74 | 84 | (defmethod process-rows ((csv copy-csv) stream process-fn)
|
75 | 85 | "Process rows from STREAM according to COPY specifications and PROCESS-FN."
|
|
0 commit comments