From: Marcus Pearce Date: Sat, 15 May 2004 10:44:54 +0000 (+0000) Subject: r9359: Fixes for PRINT-QUERY and sql concatenation operator (||). X-Git-Tag: v3.8.6~459 X-Git-Url: http://git.kpe.io/?p=clsql.git;a=commitdiff_plain;h=aad71482a312cf287e2f6e3e926cf671cd382ec7 r9359: Fixes for PRINT-QUERY and sql concatenation operator (||). --- diff --git a/ChangeLog b/ChangeLog index 42f5b29..f877f91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +15 May 2004 Marcus Pearce (m.t.pearce@city.ac.uk) + * sql/sql.lisp: PRINT-QUERY now calls QUERY with result-types and + field-names set to nil. + * sql/sql.lisp: PRINT-QUERY now computes column sizes correctly + with null attribute values. + * sql/operations.lisp: modify SQL concatenation operator to accept + unescaped || symbol. + * sql/syntax.lisp: modify sql reader macro function to accept + unescaped sql concatenation operator. + * tests/test-fdml.lisp: unescape sql concatenation operator. + * tests/test-syntax.lisp: unescape sql concatenation operator. + * TODO: remove items done. Add notes about SQLITE/MYSQL backends. + Note to add test for universal-time. Note about difference from + CommonSQL in transaction handling. + 13 May 2004 Kevin Rosenberg (kevin@rosenberg.net) * tests/test-init.lisp: Add deferred-employee-address class diff --git a/TODO b/TODO index 8563e0a..29e242c 100644 --- a/TODO +++ b/TODO @@ -9,6 +9,7 @@ TESTS TO ADD * test *db-auto-sync* * test SELECT caching * for-each-row macro +* universal-time COMMONSQL SPEC @@ -26,7 +27,6 @@ COMMONSQL SPEC nvl (Oracle specific) userenv (Oracle specific) minus (Oracle specific: does the same as EXCEPT) - || o variables (e.g., table identifiers) should be instantiated at runtime @@ -56,7 +56,9 @@ MYSQL drop-index: requires a table to be specified with the :from keyword parameter views: mysql does not support views queries: nested subqueries are not supported +syntax: doesn't support the sql concatenation operator (||). SQLITE -create-view: column-list parameter not supported +create-view: column-list parameter not supported +syntax: doesn't support the sql SUBSTRING operator. diff --git a/sql/operations.lisp b/sql/operations.lisp index 9d8ef8d..d453254 100644 --- a/sql/operations.lisp +++ b/sql/operations.lisp @@ -139,7 +139,11 @@ (make-instance 'sql-relational-exp :operator 'in :sub-expressions rest)) -(defsql sql-concat (:symbol "||") (&rest rest) +;; (defsql sql-concat (:symbol "||") (&rest rest) +;; (make-instance 'sql-relational-exp +;; :operator '\|\| :sub-expressions rest)) + +(defsql sql-concat (:symbol "concat") (&rest rest) (make-instance 'sql-relational-exp :operator '\|\| :sub-expressions rest)) diff --git a/sql/sql.lisp b/sql/sql.lisp index 64f7473..0a733aa 100644 --- a/sql/sql.lisp +++ b/sql/sql.lisp @@ -71,7 +71,10 @@ default value of T, which specifies that minimum sizes are computed. The output stream is given by STREAM, which has a default value of T. This specifies that *STANDARD-OUTPUT* is used." (flet ((compute-sizes (data) - (mapcar #'(lambda (x) (apply #'max (mapcar #'length x))) + (mapcar #'(lambda (x) + (apply #'max (mapcar #'(lambda (y) + (if (null y) 3 (length y))) + x))) (apply #'mapcar (cons #'list data)))) (format-record (record control sizes) (format stream "~&~?" control @@ -80,7 +83,8 @@ value of T. This specifies that *STANDARD-OUTPUT* is used." (let* ((query-exp (etypecase query-exp (string query-exp) (sql-query (sql-output query-exp database)))) - (data (query query-exp :database database)) + (data (query query-exp :database database :result-types nil + :field-names nil)) (sizes (if (or (null sizes) (listp sizes)) sizes (compute-sizes (if titles (cons titles data) data)))) (formats (if (or (null formats) (not (listp formats))) diff --git a/sql/syntax.lisp b/sql/syntax.lisp index 5a713d0..7a619f0 100644 --- a/sql/syntax.lisp +++ b/sql/syntax.lisp @@ -84,9 +84,11 @@ syntax is disabled." (defun sql-reader-open (stream char) (declare (ignore char)) (let ((sqllist (read-delimited-list #\] stream t))) - (if (sql-operator (car sqllist)) - (cons (sql-operator (car sqllist)) (cdr sqllist)) - (apply #'generate-sql-reference sqllist)))) + (cond ((string= (write-to-string (car sqllist)) "||") + (cons (sql-operator 'concat) (cdr sqllist))) + ((sql-operator (car sqllist)) + (cons (sql-operator (car sqllist)) (cdr sqllist))) + (t (apply #'generate-sql-reference sqllist))))) ;; Internal function that disables the close syntax when leaving sql context. (defun disable-sql-close-syntax () diff --git a/tests/test-fdml.lisp b/tests/test-fdml.lisp index 0286b2d..ca491ac 100644 --- a/tests/test-fdml.lisp +++ b/tests/test-fdml.lisp @@ -356,7 +356,7 @@ ("Vlad" "Jose" "Leon" "Niki" "Leon" "Yuri" "Kons" "Mikh" "Bori" "Vlad")) (deftest :fdml/select/22 - (clsql:select [\|\| [first-name] " " [last-name]] :from [employee] + (clsql:select [|| [first-name] " " [last-name]] :from [employee] :flatp t :order-by [emplid] :field-names nil) ("Vladamir Lenin" "Josef Stalin" "Leon Trotsky" "Nikita Kruschev" "Leonid Brezhnev" "Yuri Andropov" "Konstantin Chernenko" "Mikhail Gorbachev" diff --git a/tests/test-syntax.lisp b/tests/test-syntax.lisp index ac8247e..cd8d2ba 100644 --- a/tests/test-syntax.lisp +++ b/tests/test-syntax.lisp @@ -209,7 +209,7 @@ (deftest :syntax/concat/1 - (clsql:sql [\|\| [foo] [bar] [baz]]) + (clsql:sql [|| [foo] [bar] [baz]]) "(FOO || BAR || BAZ)")