Automated commit for debian release 6.7.2-1
[clsql.git] / sql / syntax.lisp
index 436c224ccd9476b2aa3e46b88259a17ab175f037..68fa8aad7462b2e5ccacffc82d7271537a7d81b1 100644 (file)
@@ -1,8 +1,6 @@
 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
 ;;;; *************************************************************************
 ;;;;
-;;;; $Id$
-;;;;
 ;;;; CLSQL square bracket symbolic query syntax. Functions for
 ;;;; enabling and disabling the syntax and for building SQL
 ;;;; expressions using the syntax.
@@ -66,6 +64,15 @@ the current syntax state."
   '(eval-when (:compile-toplevel :load-toplevel :execute)
     (%enable-sql-reader-syntax)))
 
+(defmacro file-enable-sql-reader-syntax ()
+  "Turns on the SQL reader syntax for the rest of the file.
+The CL spec says that when finished loading a file the original
+*readtable* is restored.  clhs COMPILE-FILE"
+  '(eval-when (:compile-toplevel :load-toplevel :execute)
+    (setf *readtable* (copy-readtable))
+    (set-macro-character *sql-macro-open-char* #'sql-reader-open)
+    (set-macro-character *sql-macro-close-char* (get-macro-character #\)))))
+
 (defun %enable-sql-reader-syntax ()
   (unless *original-readtable*
     (setf *original-readtable* *readtable*
@@ -103,9 +110,17 @@ reader syntax is disabled."
 
 (defun generate-sql-reference (&rest arglist)
   (cond ((= (length arglist) 1) ; string, table or attribute
-         (if (stringp (car arglist))
-             (sql-expression :string (car arglist))
-             (sql-expression :attribute (car arglist))))
+         (let ((arg (first arglist)))
+           (typecase arg
+             (string (sql-expression :string arg))
+             (symbol ;; handle . separated names
+              (let* ((sn (symbol-name arg))
+                     (idx (position #\. sn)))
+                (cond
+                  (idx (sql-expression :table (intern (subseq sn 0 idx))
+                                       :attribute (intern (subseq sn (+ idx 1))) ))
+                  (T (sql-expression :attribute arg))))
+              ))))
         ((<= 2 (length arglist))
          (let ((sqltype (when (keywordp (caddr arglist)) (caddr arglist) nil)))
            (cond
@@ -148,7 +163,7 @@ keyword arguments is specified."
     (string
      (make-instance 'sql :string string))
     (attribute
-     (make-instance 'sql-ident-attribute  :name attribute
+     (make-instance 'sql-ident-attribute :name attribute
                     :qualifier (or table alias)
                     :type type))
     ((and table (not attribute))