X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fexpressions.lisp;h=93c97d94d8731924210e6c761b482024c859592e;hp=766da12e6a3c9dba19b628aa608617d186c4da76;hb=1b07d2fd927cf8f1943ac0a0b8c980d1dc707076;hpb=e75e62c7127f074ef2b2add3d2850c42dfaf590e diff --git a/sql/expressions.lisp b/sql/expressions.lisp index 766da12..93c97d9 100644 --- a/sql/expressions.lisp +++ b/sql/expressions.lisp @@ -22,7 +22,7 @@ (defvar *sql-stream* nil "stream which accumulates SQL output") -(defun sql-output (sql-expr &optional database) +(defun sql-output (sql-expr &optional (database *default-database*)) "Top-level call for generating SQL strings. Returns an SQL string appropriate for DATABASE which corresponds to the supplied lisp expression SQL-EXPR." @@ -390,7 +390,7 @@ (:documentation "An SQL between expression.")) (defmethod output-sql ((expr sql-between-exp) database) - (with-slots (name args) + (with-slots (args) expr (output-sql (first args) database) (write-string " BETWEEN " *sql-stream*) @@ -589,15 +589,16 @@ uninclusive, and the args from that keyword to the end." (string-equal (slot-value a 'alias) (slot-value b 'alias)) t) - (string-equal (symbol-name (slot-value a 'name)) - (symbol-name (slot-value b 'name)))))) + (string-equal (sql-escape (slot-value a 'name)) + (sql-escape (slot-value b 'name)))))) (typecase from (list (output-sql (apply #'vector (remove-duplicates from :test #'ident-table-equal)) database)) (string (write-string from *sql-stream*)) - (t (output-sql from database))))) + (t (let ((*in-subselect* t)) + (output-sql from database)))))) (when inner-join (write-string " INNER JOIN " *sql-stream*) (output-sql inner-join database)) @@ -897,6 +898,15 @@ uninclusive, and the args from that keyword to the end." database)))) (defmethod database-output-sql ((tee (eql t)) database) + (if database + (let ((val (database-output-sql-as-type 'boolean t database (database-type database)))) + (when val + (typecase val + (string (format nil "'~A'" val)) + (integer (format nil "~A" val))))) + "'Y'")) + +#+nil(defmethod database-output-sql ((tee (eql t)) database) (declare (ignore database)) "'Y'")