`(make-instance 'sql-ident :name ',name)))
(defmethod output-sql ((expr sql-ident) database)
+
(with-slots (name) expr
(write-string
(etypecase name
:type ',type)))
(defmethod output-sql ((expr sql-ident-attribute) database)
- (with-slots (qualifier name type) expr
- (if (and (not qualifier) (not type))
- (etypecase name
- (string
- (write-string name *sql-stream*))
- (symbol
- (write-string
- (sql-escape (symbol-name name)) *sql-stream*)))
-
- ;;; KMR: The TYPE field is used by CommonSQL for type conversion -- it
- ;;; should not be output in SQL statements
- #+ignore
- (format *sql-stream* "~@[~A.~]~A~@[ ~A~]"
- (when qualifier
- (sql-escape qualifier))
- (sql-escape name)
- (when type
- (symbol-name type)))
- (format *sql-stream* "~@[~A.~]~A"
- (when qualifier
- (typecase qualifier
- (string (format nil "~s" qualifier))
- (t (sql-escape qualifier))))
- (typecase name
- (string (format nil "~s" (sql-escape name)))
- (t (sql-escape name)))))
- t))
+;;; KMR: The TYPE field is used by CommonSQL for type conversion -- it
+;;; should not be output in SQL statements
+ (let ((*print-pretty* nil))
+ (with-slots (qualifier name type) expr
+ (format *sql-stream* "~@[~a.~]~a"
+ (typecase qualifier
+ (string (format nil "~s" qualifier))
+ (symbol (safety-first (sql-escape qualifier))))
+ (typecase name
+ (string (format nil "~s" name))
+ (symbol (safety-first (sql-escape name)))))
+ t)))
(defmethod output-sql-hash-key ((expr sql-ident-attribute) database)
(with-slots (qualifier name type)
(write-char #\) *sql-stream*)))
t)
+(defclass sql-array-exp (sql-relational-exp)
+ ()
+ (:documentation "An SQL relational expression."))
+
+(defmethod output-sql ((expr sql-array-exp) database)
+ (with-slots (operator sub-expressions)
+ expr
+ (let ((subs (if (consp (car sub-expressions))
+ (car sub-expressions)
+ sub-expressions)))
+ (write-char #\( *sql-stream*)
+ (output-sql operator database)
+ (write-char #\[ *sql-stream*)
+ (do ((sub subs (cdr sub)))
+ ((null (cdr sub)) (output-sql (car sub) database))
+ (output-sql (car sub) database)
+ (write-char #\, *sql-stream*)
+ (write-char #\Space *sql-stream*))
+ (write-char #\] *sql-stream*)
+ (write-char #\) *sql-stream*)))
+ t)
+
(defclass sql-upcase-like (sql-relational-exp)
()
(:documentation "An SQL 'like' that upcases its arguments."))
(write-string "SELECT " *sql-stream*)
(when all
(write-string "ALL " *sql-stream*))
+ (when (and limit (eq :odbc (database-type database)))
+ (write-string " TOP " *sql-stream*)
+ (output-sql limit database))
(when (and distinct (not all))
(write-string "DISTINCT " *sql-stream*)
(unless (eql t distinct)
(when (cdr order)
(write-char #\, *sql-stream*))))
(output-sql order-by database)))
- (when limit
+ (when (and limit (not (eq :odbc (database-type database))))
(write-string " LIMIT " *sql-stream*)
(output-sql limit database))
(when offset