Fix user defined casting rules.

Commit 598c860cf5013d52399c07c7f18f1daf0227d305 broke user defined
casting rules by interning "precision" and "scale" in the
pgloader.user-symbols package: those symbols need to be found in the
pgloader.transforms package instead.

Luckily enough the infrastructure to do that was already in place for
cl:nil.
This commit is contained in:
Dimitri Fontaine 2015-10-05 02:11:23 +02:00
parent 96a33de084
commit c880f86bb6
4 changed files with 20 additions and 10 deletions

View File

@ -6,7 +6,8 @@
(:use #:cl)
(:export #:precision
#:scale
#:intern-symbol))
#:intern-symbol
#:typemod-expr-to-function))
(defpackage #:pgloader.logs
(:use #:cl #:pgloader.params)
@ -176,7 +177,11 @@
(:use #:cl
#:pgloader.params #:pgloader.utils #:pgloader.connection
#:pgloader.schema)
(:import-from #:pgloader.transforms #:precision #:scale #:intern-symbol)
(:import-from #:pgloader.transforms
#:precision
#:scale
#:intern-symbol
#:typemod-expr-to-function)
(:import-from #:pgloader.parse-date
#:parse-date-string
#:parse-date-format)

View File

@ -266,7 +266,11 @@
(defrule sexp-symbol (and (symbol-first-character-p character)
(* (symbol-character-p character)))
(:lambda (schars)
(pgloader.transforms:intern-symbol (text schars) '(("nil" . cl:nil)))))
(pgloader.transforms:intern-symbol
(text schars)
'(("nil" . cl:nil)
("precision" . pgloader.transforms::precision)
("scale" . pgloader.transforms::scale)))))
(defrule sexp-string-char (or (not-doublequote character) (and #\\ #\")))

View File

@ -29,13 +29,6 @@
:start (+ 1 start-1) :end end))
(cons a b))))))
(defun typemod-expr-to-function (expr)
"Transform given EXPR into a callable function object."
`(lambda (typemod)
(destructuring-bind (precision &optional (scale 0)) typemod
(declare (ignorable precision scale))
,expr)))
(defun typemod-expr-matches-p (rule-typemod-expr typemod)
"Check if an expression such as (< 10) matches given typemod."
(funcall (compile nil (typemod-expr-to-function rule-typemod-expr)) typemod))

View File

@ -41,6 +41,14 @@
(intern (string-upcase symbol-name)
(find-package "PGLOADER.USER-SYMBOLS"))))))))
(defun typemod-expr-to-function (expr)
"Transform given EXPR into a callable function object."
`(lambda (typemod)
(destructuring-bind (precision &optional (scale 0))
typemod
(declare (ignorable precision scale))
,expr)))
;;;
;;; Some optimisation stanza