From 36805afc6478e39cf5c84406ab73c6fbd28bf8b5 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 26 May 2014 11:01:19 +0200 Subject: [PATCH] Fix *csv-path-root* at run-time. When using LOAD CSV it's possible to load from filename matching a regular expression, but for that to work the *csv-path-root* needs to be properly setup at run-time. --- src/parser.lisp | 1 + test/csv-filename-pattern.load | 10 ++++++++++ test/data/matching-1.csv | 1 + test/data/matching-2.csv | 1 + test/data/matching-3.csv | 1 + 5 files changed, 14 insertions(+) create mode 100644 test/csv-filename-pattern.load create mode 100644 test/data/matching-1.csv create mode 100644 test/data/matching-2.csv create mode 100644 test/data/matching-3.csv diff --git a/src/parser.lisp b/src/parser.lisp index 86a0c3d..3f2906e 100644 --- a/src/parser.lisp +++ b/src/parser.lisp @@ -1698,6 +1698,7 @@ load database (summary (null *state*)) (*state* (or *state* (pgloader.utils:make-pgstate))) (state-after ,(when after `(pgloader.utils:make-pgstate))) + (*csv-path-root* ,*cwd*) ,@(pgsql-connection-bindings pg-db-uri gucs) ,@(batch-control-bindings options)) diff --git a/test/csv-filename-pattern.load b/test/csv-filename-pattern.load new file mode 100644 index 0000000..548782b --- /dev/null +++ b/test/csv-filename-pattern.load @@ -0,0 +1,10 @@ +load csv + from all filenames matching ~ (id, field) + into postgresql:///pgloader?matching + with fields optionally enclosed by '"', + fields terminated by ',', + truncate + + before load do + $$ drop table if exists matching; $$, + $$ create table matching(id int, field text); $$; diff --git a/test/data/matching-1.csv b/test/data/matching-1.csv new file mode 100644 index 0000000..7745fb4 --- /dev/null +++ b/test/data/matching-1.csv @@ -0,0 +1 @@ +1,"foo" diff --git a/test/data/matching-2.csv b/test/data/matching-2.csv new file mode 100644 index 0000000..044cfe0 --- /dev/null +++ b/test/data/matching-2.csv @@ -0,0 +1 @@ +2,"bar" diff --git a/test/data/matching-3.csv b/test/data/matching-3.csv new file mode 100644 index 0000000..bee5a20 --- /dev/null +++ b/test/data/matching-3.csv @@ -0,0 +1 @@ +3,"baz"