From 62f0b7fc56c5977d602a99f485348b4b86179758 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 31 Aug 2015 20:34:22 +0200 Subject: [PATCH] Support String Constants with Escapes in SQL files. pgloader has to parse external SQL files because of the driver we use, Postmodern, only know how to deal with sending one query at a time. So SQL parsing we do, and split the queries, and send them one after the other to the server. PostgreSQL allows String Constants with C-style Escapes to be used in some situations, and the SQL parsing done in pgloader failed to support that. http://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE This fixes #284. --- src/utils/read-sql-files.lisp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils/read-sql-files.lisp b/src/utils/read-sql-files.lisp index 179e1d1..f2bbbe4 100644 --- a/src/utils/read-sql-files.lisp +++ b/src/utils/read-sql-files.lisp @@ -160,6 +160,15 @@ Another test case for the classic quotes: (otherwise (cond ((member (parser-state state) '(:eat :eqt)) (write-char char (parser-stream state))) + ;; see + ;; http://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE + ;; we re-inject whatever we read in the \x + ;; syntax into the stream and let PostgreSQL + ;; be the judge of what it means. + ((member (parser-state state) '(:esc)) + (write-char char (parser-stream state)) + (setf (parser-state state) :eqt)) + ((member (parser-state state) '(:tag)) ;; only letters are allowed in tags (if (alpha-char-p char)