mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-05 02:46:10 +02:00
Some default values come properly quoted from MariaDB now.
Adjust the default value formating to check if the default value is already single-quoted and only add new 'single quotes' when it's not the case. Apparently ENUM default values in MariaDB 10 are now properly single quoted.
This commit is contained in:
parent
dfac729daa
commit
987c0703ad
@ -35,6 +35,7 @@
|
||||
(:export #:apply-identifier-case
|
||||
#:build-identifier
|
||||
#:quoted-p
|
||||
#:ensure-quoted
|
||||
#:ensure-unquoted
|
||||
#:camelCase-to-colname))
|
||||
|
||||
|
||||
@ -144,7 +144,7 @@
|
||||
(make-column :default transformed-default)))
|
||||
(format-default-value transformed-column))
|
||||
(if default
|
||||
(format stream "'~a'" default)
|
||||
(ensure-quoted default #\')
|
||||
(format stream "NULL"))))))
|
||||
|
||||
|
||||
|
||||
@ -7,11 +7,6 @@
|
||||
|
||||
(in-package :pgloader.quoting)
|
||||
|
||||
(defun quoted-p (s)
|
||||
"Return true if s is a double-quoted string"
|
||||
(and (eq (char s 0) #\")
|
||||
(eq (char s (- (length s) 1)) #\")))
|
||||
|
||||
(defun apply-identifier-case (identifier)
|
||||
"Return given IDENTIFIER with CASE handled to be PostgreSQL compatible."
|
||||
(let* ((lowercase-identifier (cl-ppcre:regex-replace-all
|
||||
@ -47,6 +42,11 @@
|
||||
(cl-ppcre:regex-replace-all "\"" identifier "\"\"")))
|
||||
(:none identifier))))
|
||||
|
||||
(defun quoted-p (s &optional (quote-char #\"))
|
||||
"Return true if s is a double-quoted string"
|
||||
(and (eq (char s 0) quote-char)
|
||||
(eq (char s (- (length s) 1)) quote-char)))
|
||||
|
||||
(defun ensure-unquoted (identifier)
|
||||
(cond ((quoted-p identifier)
|
||||
;; when the table name comes from the user (e.g. in the
|
||||
@ -57,6 +57,11 @@
|
||||
|
||||
(t identifier)))
|
||||
|
||||
(defun ensure-quoted (value &optional (quote-char #\"))
|
||||
(if (quoted-p value quote-char)
|
||||
value
|
||||
(format nil "~c~a~c" quote-char value quote-char)))
|
||||
|
||||
(defun build-identifier (sep &rest parts)
|
||||
"Concatenante PARTS into a PostgreSQL identifier, with SEP in between
|
||||
parts. That's useful for creating an index name from a table's oid and name."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user