projects
/
clsql.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
New release 5.2.0
[clsql.git]
/
sql
/
expressions.lisp
diff --git
a/sql/expressions.lisp
b/sql/expressions.lisp
index 2cb7339251b6d425b20c7a362f88a1a3bac9d866..5e75b01ccdfaaae1842dabe6dea7179cb77674e0 100644
(file)
--- a/
sql/expressions.lisp
+++ b/
sql/expressions.lisp
@@
-1,8
+1,6
@@
;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
;;;; *************************************************************************
;;;;
;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
;;;; *************************************************************************
;;;;
-;;;; $Id$
-;;;;
;;;; Classes defining SQL expressions and methods for formatting the
;;;; appropriate SQL commands.
;;;;
;;;; Classes defining SQL expressions and methods for formatting the
;;;; appropriate SQL commands.
;;;;
@@
-194,15
+192,25
@@
sql
`(make-instance 'sql-ident-table :name ',name :table-alias ',alias)))
sql
`(make-instance 'sql-ident-table :name ',name :table-alias ',alias)))
+(defun special-char-p (s)
+ "Check if a string has any special characters"
+ (loop for char across s
+ thereis (find char '(#\space #\, #\. #\! #\@ #\# #\$ #\%
+ #\^ #\& #\* #\| #\( #\) #\- #\+))))
+
(defmethod output-sql ((expr sql-ident-table) database)
(with-slots (name alias) expr
(defmethod output-sql ((expr sql-ident-table) database)
(with-slots (name alias) expr
- (etypecase name
- (string
- (format *sql-stream* "~s" (sql-escape name)))
- (symbol
- (write-string (sql-escape name) *sql-stream*)))
- (when alias
- (format *sql-stream* " ~s" alias)))
+ (flet ((p (s) ;; the etypecase is in sql-escape too
+ (let ((sym? (symbolp s))
+ (s (sql-escape s)))
+ (format *sql-stream*
+ (if (and sym? (not (special-char-p s)))
+ "~a" "~s")
+ s))))
+ (p name)
+ (when alias
+ (princ #\space *sql-stream*)
+ (p alias))))
t)
(defmethod output-sql-hash-key ((expr sql-ident-table) database)
t)
(defmethod output-sql-hash-key ((expr sql-ident-table) database)
@@
-249,7
+257,7
@@
;; the next loop simply emits each sub-expression with the appropriate number of
;; parens and operators
(flet ((trim (sub)
;; the next loop simply emits each sub-expression with the appropriate number of
;; parens and operators
(flet ((trim (sub)
- (string-trim
'(#\space #\newline #\return #\tab #\no-break_space)
+ (string-trim
+whitespace-chars+
(with-output-to-string (*sql-stream*)
(output-sql sub database)))))
(let ((str-subs (loop for sub in sub-expressions
(with-output-to-string (*sql-stream*)
(output-sql sub database)))))
(let ((str-subs (loop for sub in sub-expressions