-2012-03-25 Ryan Davis <ryan@acceleration.net>
-
- * sql/expressions.lisp:
-
- Fixed bugs related to outputting where clauses in delete/updates
- using sql syntax. Previously subselects and where clauses without
- data (such as an empty or clause or and clause) would cause
- failures.
+2012-03-27 Ryan Davis <ryan@acceleration.net>
+
+ * sql/expressions.lisp: Fixed bug with subqueries in the where
+ clause of update-records and delete-records generating invalid
+ SQL. Previously subselects in where clauses would not have enough
+ parentheses, for example: "WHERE Id IN SELECT foo_id FROM bar"
+ vs. "WHERE Id IN (SELECT foo_id FROM bar)"
+ * tests/test-syntax.lisp: Added tests for using subqueries in the
+ where clause in update-records and delete-records. Moved asserts
+ in the test-output-sql/sql-ident-table function into the standard
+ test framework.
+ * doc/appendix.xml: added :connection-string to the information on
+ ODBC connection specs, and added example code connecting to ODBC
+ databases.
2012-02-22 Nathan Bird <nathan@acceleration.net>
[like (clsql:sql-expression :table table
:attribute 'baz)
(clsql:sql table)])))
- "(BETWEEN(THISTIME.BAR,(HIP * HOP),42) AND (THISTIME.BAZ LIKE 'THISTIME') AND BETWEEN(NEXTTIME.BAR,(HIP * HOP),43) AND (NEXTTIME.BAZ LIKE 'NEXTTIME') AND BETWEEN(SOMETIME.BAR,(HIP * HOP),44) AND (SOMETIME.BAZ LIKE 'SOMETIME') AND BETWEEN(NEVER.BAR,(HIP * HOP),45) AND (NEVER.BAZ LIKE 'NEVER'))")
-
-))
-
-(defun test-output-sql/sql-ident-table ()
- (let ((tests `((,(make-instance 'sql-ident-table :name :foo) "FOO")
- (,(make-instance 'sql-ident-table :name :foo-bar) "FOO_BAR")
- (,(make-instance 'sql-ident-table :name "foo") "\"foo\"")
- (,(make-instance 'sql-ident-table :name '|foo bar|) "\"foo bar\"")
- (,(make-instance 'sql-ident-table :name :foo :table-alias :bar) "FOO BAR" )
- (,(make-instance 'sql-ident-table :name :foo_bar :table-alias :bar-bast) "FOO_BAR BAR_BAST")
- (,(make-instance 'sql-ident-table :name "foo" :table-alias "Bar") "\"foo\" \"Bar\"")
- (,(make-instance 'sql-ident-table :name '|foo bar| :table-alias :bast) "\"foo bar\" BAST"))))
- (loop for (test expected-result) in tests
- for test-out = (with-output-to-string (*sql-stream*) (output-sql test nil))
- do (assert (string-equal test-out expected-result)
- (test test-out expected-result)
- "Test:~s didnt match ~S"
- test-out expected-result))))
+ "(BETWEEN(THISTIME.BAR,(HIP * HOP),42) AND (THISTIME.BAZ LIKE 'THISTIME') AND BETWEEN(NEXTTIME.BAR,(HIP * HOP),43) AND (NEXTTIME.BAZ LIKE 'NEXTTIME') AND BETWEEN(SOMETIME.BAR,(HIP * HOP),44) AND (SOMETIME.BAZ LIKE 'SOMETIME') AND BETWEEN(NEVER.BAR,(HIP * HOP),45) AND (NEVER.BAZ LIKE 'NEVER'))"
+ )
+
+(deftest :syntax/subqueries/query
+ (clsql:sql
+ (clsql:sql-operation 'select [*]
+ :from [foo]
+ :where [in [id] [select [id] :from [bar]]]))
+ "SELECT * FROM FOO WHERE (ID IN (SELECT ID FROM BAR))")
+
+(deftest :syntax/subqueries/delete
+ (clsql:sql
+ (make-instance 'clsql-sys::sql-delete
+ :from [foo]
+ :where [in [id] [select [id] :from [bar]]]))
+ "DELETE FROM FOO WHERE (ID IN (SELECT ID FROM BAR))")
+
+(deftest :syntax/subqueries/update
+ (clsql:sql
+ (make-instance 'clsql-sys::sql-update
+ :attributes (list [id])
+ :values '(0)
+ :table [foo]
+ :where [in [id] [select [id] :from [bar]]]))
+ "UPDATE FOO SET ID = 0 WHERE (ID IN (SELECT ID FROM BAR))")
+
+ ))
+
+(let ((tests '(((:foo) "FOO")
+ ((:foo-bar) "FOO_BAR")
+ (("foo") "\"foo\"")
+ (('|foo bar|) "\"foo bar\"")
+ ((:foo :table-alias :bar) "FOO BAR" )
+ ((:foo_bar :table-alias :bar-bast) "FOO_BAR BAR_BAST")
+ (("foo" :table-alias "Bar") "\"foo\" \"Bar\"")
+ (('|foo bar| :table-alias :bast) "\"foo bar\" BAST"))))
+
+ (push
+ `(deftest :syntax/sql-ident-table
+ (values ,@(mapcar
+ #'(lambda (args)
+ `(clsql:sql (make-instance 'clsql-sys:sql-ident-table
+ :name ,@args)))
+ (mapcar #'first tests)))
+ ,@(mapcar #'second tests))
+ *rt-syntax*))