From 86d84b96f3e70bbb52c5701ec8f0eee611a3b3c9 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Tue, 6 Apr 2004 14:44:30 +0000 Subject: [PATCH] r8835: integration improvements --- clsql.asd | 2 +- sql/sql.lisp | 57 +++++++++++++++++++++++++-------------------------- sql/usql.lisp | 3 +++ 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/clsql.asd b/clsql.asd index cef8387..324ff5d 100644 --- a/clsql.asd +++ b/clsql.asd @@ -24,7 +24,7 @@ :name "clsql" :author "Kevin Rosenberg " :maintainer "Kevin M. Rosenberg " - :version "1.5.x" + :version "2.1.x" :licence "Lessor Lisp General Public License" :description "Common Lisp SQL Interface Library" :long-description "cl-sql package provides the high-level interface for the CLSQL system." diff --git a/sql/sql.lisp b/sql/sql.lisp index 7e36da8..c207a8f 100644 --- a/sql/sql.lisp +++ b/sql/sql.lisp @@ -22,7 +22,35 @@ ;;; Row processing macro +(defmacro for-each-row (((&rest fields) &key from order-by where distinct limit) &body body) + (let ((d (gensym "DISTINCT-")) + (bind-fields (loop for f in fields collect (car f))) + (w (gensym "WHERE-")) + (o (gensym "ORDER-BY-")) + (frm (gensym "FROM-")) + (l (gensym "LIMIT-")) + (q (gensym "QUERY-"))) + `(let ((,frm ,from) + (,w ,where) + (,d ,distinct) + (,l ,limit) + (,o ,order-by)) + (let ((,q (query-string ',fields ,frm ,w ,d ,o ,l))) + (loop for tuple in (query ,q) + collect (destructuring-bind ,bind-fields tuple + ,@body)))))) +(defun query-string (fields from where distinct order-by limit) + (concatenate + 'string + (format nil "select ~A~{~A~^,~} from ~{~A~^ and ~}" + (if distinct "distinct " "") (field-names fields) + (from-names from)) + (if where (format nil " where ~{~A~^ ~}" + (where-strings where)) "") + (if order-by (format nil " order by ~{~A~^, ~}" + (order-by-strings order-by))) + (if limit (format nil " limit ~D" limit) ""))) (defun lisp->sql-name (field) (typecase field @@ -61,35 +89,6 @@ (format nil "~A ~A" (lisp->sql-name (car o)) (lisp->sql-name (cadr o)))))) -(defun query-string (fields from where distinct order-by limit) - (concatenate - 'string - (format nil "select ~A~{~A~^,~} from ~{~A~^ and ~}" - (if distinct "distinct " "") (field-names fields) - (from-names from)) - (if where (format nil " where ~{~A~^ ~}" - (where-strings where)) "") - (if order-by (format nil " order by ~{~A~^, ~}" - (order-by-strings order-by))) - (if limit (format nil " limit ~D" limit) ""))) - -(defmacro for-each-row (((&rest fields) &key from order-by where distinct limit) &body body) - (let ((d (gensym "DISTINCT-")) - (bind-fields (loop for f in fields collect (car f))) - (w (gensym "WHERE-")) - (o (gensym "ORDER-BY-")) - (frm (gensym "FROM-")) - (l (gensym "LIMIT-")) - (q (gensym "QUERY-"))) - `(let ((,frm ,from) - (,w ,where) - (,d ,distinct) - (,l ,limit) - (,o ,order-by)) - (let ((,q (query-string ',fields ,frm ,w ,d ,o ,l))) - (loop for tuple in (query ,q) - collect (destructuring-bind ,bind-fields tuple - ,@body)))))) ;;; Marc Battyani : Large objects support diff --git a/sql/usql.lisp b/sql/usql.lisp index 472de2d..1acd88a 100644 --- a/sql/usql.lisp +++ b/sql/usql.lisp @@ -20,6 +20,9 @@ ;;; Minimal high-level routines to enable low-level interface for USQL +;;; Thse functions are not exported. If you application depends on these +;;; consider using the clsql-usql package. + (in-package #:clsql-sys) -- 2.34.1