From f7d251ed86df76a1b4c397d764fce0657696eb8c Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Fri, 20 Jun 2014 13:10:39 +0200 Subject: [PATCH] Fix quoting of TRUNCATE command, fix #84. That patch is not a principaled approach at fixing the problem but should allow for not messing up with fully qualified table names. A proper way to do it would be to have a pgsql object name structure composed of the catalog, the schema and the name as separate entries, with assorted API to print that object properly. That's for another day though. --- src/pgsql/schema.lisp | 4 ++-- test/csv-before-after.load | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pgsql/schema.lisp b/src/pgsql/schema.lisp index c63b23a..b0f22d5 100644 --- a/src/pgsql/schema.lisp +++ b/src/pgsql/schema.lisp @@ -14,7 +14,7 @@ case))) (ecase case (:downcase (cl-ppcre:regex-replace-all - "[^a-zA-Z0-9]" (string-downcase identifier) "_")) + "[^a-zA-Z0-9.]" (string-downcase identifier) "_")) (:quote (format nil "\"~a\"" identifier))))) ;;; @@ -189,7 +189,7 @@ "Truncate given TABLE-NAME in database DBNAME" (pomo:with-connection (get-connection-spec dbname) (set-session-gucs *pg-settings*) - (let ((sql (format nil "TRUNCATE ~{~s~^,~};" + (let ((sql (format nil "TRUNCATE ~{~a~^,~};" (loop :for table-name :in table-name-list :collect (apply-identifier-case table-name identifier-case))))) diff --git a/test/csv-before-after.load b/test/csv-before-after.load index efc5490..0af3fd3 100644 --- a/test/csv-before-after.load +++ b/test/csv-before-after.load @@ -9,7 +9,8 @@ LOAD CSV iprange ip4r using (ip-range startIpNum endIpNum), locId ) - WITH fields optionally enclosed by '"', + WITH truncate, + fields optionally enclosed by '"', fields escaped by double-quote, fields terminated by ',' @@ -17,7 +18,7 @@ LOAD CSV BEFORE LOAD DO $$ create extension if not exists ip4r; $$, - $$ drop schema if exists csv; $$, + $$ drop schema if exists csv cascade; $$, $$ create schema csv; $$, $$ create table if not exists csv.blocks (