X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Fclasses.lisp;h=bf74b6ecc3e4c8e6f01fee30820eaa91517421bf;hb=b2ff4969e20cce173d403de7542d5bf0e46938d7;hp=af3ca8db3fdbecd86ad9719d1a886387a3372f92;hpb=e303385b84c6246c7d60ebd95d764a282a181a23;p=clsql.git diff --git a/sql/classes.lisp b/sql/classes.lisp index af3ca8d..bf74b6e 100644 --- a/sql/classes.lisp +++ b/sql/classes.lisp @@ -119,10 +119,7 @@ :initform "NULL") (type :initarg :type - :initform "NULL") - (params - :initarg :params - :initform nil)) + :initform "NULL")) (:documentation "An SQL Attribute identifier.")) (defmethod collect-table-refs (sql) @@ -144,7 +141,7 @@ :type ',type))) (defmethod output-sql ((expr sql-ident-attribute) database) - (with-slots (qualifier name type params) + (with-slots (qualifier name type) expr (if (and (not qualifier) (not type)) (write-string (sql-escape (convert-to-db-default-case @@ -169,9 +166,9 @@ (defmethod output-sql-hash-key ((expr sql-ident-attribute) database) (declare (ignore database)) - (with-slots (qualifier name type params) + (with-slots (qualifier name type) expr - (list 'sql-ident-attribute qualifier name type params))) + (list 'sql-ident-attribute qualifier name type))) ;; For SQL Identifiers for tables (defclass sql-ident-table (sql-ident) @@ -487,9 +484,6 @@ (order-by :initarg :order-by :initform nil) - (order-by-descending - :initarg :order-by-descending - :initform nil) (inner-join :initarg :inner-join :initform nil) @@ -520,8 +514,7 @@ (defvar *select-arguments* '(:all :database :distinct :flatp :from :group-by :having :order-by - :order-by-descending :set-operation :where :offset :limit - :inner-join :on + :set-operation :where :offset :limit :inner-join :on ;; below keywords are not a SQL argument, but these keywords may terminate select :caching :refresh)) @@ -552,7 +545,7 @@ uninclusive, and the args from that keyword to the end." :flatp flatp :refresh refresh :exp arglist)) (destructuring-bind (&key all flatp set-operation distinct from where - group-by having order-by order-by-descending + group-by having order-by offset limit inner-join on &allow-other-keys) arglist (if (null selections) @@ -564,15 +557,13 @@ uninclusive, and the args from that keyword to the end." :distinct distinct :from from :where where :limit limit :offset offset :group-by group-by :having having :order-by order-by - :order-by-descending order-by-descending :inner-join inner-join :on on)))))) (defvar *in-subselect* nil) (defmethod output-sql ((query sql-query) database) (with-slots (distinct selections from where group-by having order-by - order-by-descending limit offset inner-join on - all set-operation) + limit offset inner-join on all set-operation) query (when *in-subselect* (write-string "(" *sql-stream*)) @@ -625,16 +616,6 @@ uninclusive, and the args from that keyword to the end." (when (cdr order) (write-char #\, *sql-stream*)))) (output-sql order-by database))) - (when order-by-descending - (write-string " ORDER BY " *sql-stream*) - (if (listp order-by-descending) - (do ((order order-by-descending (cdr order))) - ((null order)) - (output-sql (car order) database) - (when (cdr order) - (write-char #\, *sql-stream*))) - (output-sql order-by-descending database)) - (write-string " DESC " *sql-stream*)) (when limit (write-string " LIMIT " *sql-stream*) (output-sql limit database)) @@ -786,8 +767,11 @@ uninclusive, and the args from that keyword to the end." (if (stringp db-type) db-type ; override definition (database-get-type-specifier (car type) (cdr type) database)) *sql-stream*) - (let ((constraints - (database-constraint-statement constraints database))) + (let ((constraints (database-constraint-statement + (if (and db-type (symbolp db-type)) + (cons db-type constraints) + constraints) + database))) (when constraints (write-string " " *sql-stream*) (write-string constraints *sql-stream*))))))) @@ -840,7 +824,11 @@ uninclusive, and the args from that keyword to the end." (defparameter *constraint-types* (list (cons (symbol-name-default-case "NOT-NULL") "NOT NULL") - (cons (symbol-name-default-case "PRIMARY-KEY") "PRIMARY KEY"))) + (cons (symbol-name-default-case "PRIMARY-KEY") "PRIMARY KEY") + (cons (symbol-name-default-case "NOT") "NOT") + (cons (symbol-name-default-case "NULL") "NULL") + (cons (symbol-name-default-case "PRIMARY") "PRIMARY") + (cons (symbol-name-default-case "KEY") "KEY"))) ;; ;; Convert type spec to sql syntax @@ -851,9 +839,9 @@ uninclusive, and the args from that keyword to the end." (let ((output (assoc (symbol-name constraint) *constraint-types* :test #'equal))) (if (null output) - (error 'clsql-sql-syntax-error - :reason (format nil "unsupported column constraint '~a'" - constraint)) + (error 'sql-user-error + :message (format nil "unsupported column constraint '~A'" + constraint)) (cdr output)))) (defmethod database-constraint-statement (constraint-list database) @@ -869,9 +857,9 @@ uninclusive, and the args from that keyword to the end." *constraint-types* :test #'equal))) (if (null output) - (error 'clsql-sql-syntax-error - :reason (format nil "unsupported column constraint '~a'" - constraint)) + (error 'sql-user-error + :message (format nil "unsupported column constraint '~A'" + constraint)) (setq string (concatenate 'string string (cdr output)))) (if (< 1 (length constraint)) (setq string (concatenate 'string string " "))))))))