From: Marcus Pearce Date: Sat, 15 May 2004 13:07:11 +0000 (+0000) Subject: r9361: Support for qualified sql identifiers with aliased table names. X-Git-Tag: v3.8.6~457 X-Git-Url: http://git.kpe.io/?p=clsql.git;a=commitdiff_plain;h=21ffe5f820036726c6353a16dfb478fb41aa700c r9361: Support for qualified sql identifiers with aliased table names. --- diff --git a/ChangeLog b/ChangeLog index 6fe98ec..ada36bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,10 @@ 15 May 2004 Marcus Pearce (m.t.pearce@city.ac.uk) * sql/classes.lisp: SELECT now accepts table identifiers as strings - for CommonSQL compliance. - * tests/test-fdml.lisp: added test for table identifiers as strings - in SELECT. + for CommonSQL compliance. Add support for qualified sql identifiers + with aliased table names. + * tests/test-fdml.lisp: added tests for table identifiers as strings + in SELECT and for aliased definitions. + * tests/test-syntax.lisp: added tests for alias definitions. 15 May 2004 Marcus Pearce (m.t.pearce@city.ac.uk) * sql/sql.lisp: PRINT-QUERY now calls QUERY with result-types and diff --git a/sql/classes.lisp b/sql/classes.lisp index 4e697ca..872830f 100644 --- a/sql/classes.lisp +++ b/sql/classes.lisp @@ -160,7 +160,10 @@ (convert-to-db-default-case (symbol-name type) database))) (format *sql-stream* "~@[~A.~]~A" (when qualifier - (convert-to-db-default-case (sql-escape qualifier) database)) + (typecase qualifier + (string (format nil "~s" qualifier)) + (t (convert-to-db-default-case (sql-escape qualifier) + database)))) (sql-escape (convert-to-db-default-case name database)))) t)) @@ -581,7 +584,9 @@ uninclusive, and the args from that keyword to the end." (write-string " FROM " *sql-stream*) (typecase from (list (output-sql (apply #'vector from) database)) - (string (write-string from *sql-stream*)) + (string (write-string + (sql-escape + (convert-to-db-default-case from database)) *sql-stream*)) (t (output-sql from database)))) (when inner-join (write-string " INNER JOIN " *sql-stream*) diff --git a/tests/test-fdml.lisp b/tests/test-fdml.lisp index 8f9fd3f..33267a5 100644 --- a/tests/test-fdml.lisp +++ b/tests/test-fdml.lisp @@ -382,6 +382,17 @@ ("Boris" "Josef" "Konstantin" "Leon" "Leonid" "Mikhail" "Nikita" "Vladamir" "Yuri")) +(deftest :fdml/select/26 + (clsql:select ["table" first-name] ["table" last-name] + :from '([employee "table"] [employee "join"]) + :where [and [= ["table" first-name] + ["join" first-name]] + [not [= ["table" emplid] + ["join" emplid]]]] + :order-by '(["table" last-name]) + :result-types nil :field-names nil) + (("Vladamir" "Lenin") ("Vladamir" "Putin"))) + ;(deftest :fdml/select/11 ; (clsql:select [emplid] :from [employee] ; :where [= [emplid] [any [select [companyid] :from [company]]]] diff --git a/tests/test-syntax.lisp b/tests/test-syntax.lisp index cd8d2ba..8d1a863 100644 --- a/tests/test-syntax.lisp +++ b/tests/test-syntax.lisp @@ -50,24 +50,25 @@ "FOO.BAR") (deftest :syntax/ident/3 - (clsql:sql ["foo" bar]) - "FOO.BAR") - -;(deftest :syntax/ident/4 -; (clsql:sql [foo "bar"]) -; "FOO \"bar\"") - -(deftest :syntax/ident/5 (clsql:sql [foo :integer]) "FOO") -(deftest :syntax/ident/6 +(deftest :syntax/ident/4 (clsql:sql [foo bar :integer]) "FOO.BAR") +(deftest :syntax/ident/5 + (clsql:sql [foo "bar"]) + "FOO \"bar\"") + +(deftest :syntax/ident/6 + (clsql:sql ["foo" bar]) + "\"foo\".BAR") + (deftest :syntax/ident/7 (clsql:sql ["foo" bar :integer]) - "FOO.BAR") + "\"foo\".BAR") + (deftest :syntax/subquery/1