improved and moved command object up to clsql (out of cl-postgres-socket3)
authorRuss Tyndall <russ@acceleration.net>
Wed, 8 Jun 2011 21:05:47 +0000 (17:05 -0400)
committerNathan Bird <nathan@acceleration.net>
Thu, 30 Jun 2011 20:56:28 +0000 (16:56 -0400)
 * added command-object fn
 * added reset-command-object
 * command-objects: made nil be treated as "null" in the database by default instead of "false". To pass false use :false or :f

 prev: d704ea35ebc38b6b9efd5cbb0417d0340bee3c5c
       1e8d22b3fdace44a45b6b0702da5587e136e2398
       f6651e31a95d4df2481ebaca270d35fa16b6be13
       051f4d2f472406fa381e20d2da0cf25f091f262a
       f3430ff34ef6631daf20cb9c69ecbc7ad84d14df

clsql-postgresql-socket3.asd
clsql.asd
db-postgresql-socket3/command-object.lisp [deleted file]
sql/command-object.lisp [new file with mode: 0644]
sql/package.lisp

index 901057ac4f93a1afa63fbe581013655890e278a2..4f4bd2544a0c604fd506432dfd5fdd1d3bffa787 100644 (file)
@@ -33,7 +33,6 @@
   :components
   ((:module :db-postgresql-socket3
            :serial T
-           :components ((:file "command-object")
-                        (:file "package")
+           :components ((:file "package")
                         (:file "api")
                         (:file "sql")))))
index 7c9700541669379adf1885572277bf771159b478..9366281d3c44496f605e4f8d7a68f7c78316f694 100644 (file)
--- a/clsql.asd
+++ b/clsql.asd
@@ -88,7 +88,8 @@ oriented interface."
                        :pathname ""
                        :components ((:file "generic-postgresql")
                                     (:file "generic-odbc")
-                                    (:file "sequences"))
+                                    (:file "sequences")
+                                    (:file "command-object"))
                        :depends-on (functional))))))
 
 
diff --git a/db-postgresql-socket3/command-object.lisp b/db-postgresql-socket3/command-object.lisp
deleted file mode 100644 (file)
index 47dad33..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
-;;;; *************************************************************************
-;;;; FILE IDENTIFICATION
-;;;;
-;;;; Name:     postgresql-socket-sql.sql
-;;;; Purpose:  High-level PostgreSQL interface using socket
-;;;; Authors:  Russ Tyndall (at Acceleration.net) based on original code by
-;;;;           Kevin M. Rosenberg based on original code by Pierre R. Mai
-;;;; Created:  Sep 2009
-;;;;
-;;;;
-;;;; $Id$
-;;;;
-;;;; This file, part of CLSQL, is Copyright (c) 2002-2007 by Kevin M. Rosenberg
-;;;; and Copyright (c) 1999-2001 by Pierre R. Mai
-;;;;
-;;;; CLSQL users are granted the rights to distribute and use this software
-;;;; as governed by the terms of the Lisp Lesser GNU Public License
-;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
-;;;;
-;;;; *************************************************************************
-
-(in-package #:clsql-sys)
-
-(defclass command-object ()
-  ((expression :accessor expression :initarg :expression :initform nil)
-   (parameters :accessor parameters :initarg :parameters :initform nil)
-   (prepared-name :accessor prepared-name :initarg :prepared-name :initform ""
-    :documentation "If we want this to be a prepared statement, give it a name
-       to identify it to this session")
-   (has-been-prepared :accessor has-been-prepared :initarg :has-been-prepared :initform nil
-                     :documentation "Have we already prepared this command object")
-   ))
-
-(export '(expression parameters prepared-name has-been-prepared command-object))
-
-
diff --git a/sql/command-object.lisp b/sql/command-object.lisp
new file mode 100644 (file)
index 0000000..3b752ef
--- /dev/null
@@ -0,0 +1,58 @@
+;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:     postgresql-socket-sql.sql
+;;;; Purpose:  High-level PostgreSQL interface using socket
+;;;; Authors:  Russ Tyndall (at Acceleration.net) based on original code by
+;;;;           Kevin M. Rosenberg based on original code by Pierre R. Mai
+;;;; Created:  Sep 2009
+;;;;
+;;;;
+;;;; $Id$
+;;;;
+;;;; This file, part of CLSQL, is Copyright (c) 2002-2007 by Kevin M. Rosenberg
+;;;; and Copyright (c) 1999-2001 by Pierre R. Mai
+;;;;
+;;;; CLSQL users are granted the rights to distribute and use this software
+;;;; as governed by the terms of the Lisp Lesser GNU Public License
+;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
+;;;;
+;;;; *************************************************************************
+
+(in-package #:clsql-sys)
+
+(defclass command-object ()
+  ((expression :accessor expression :initarg :expression :initform nil)
+   (parameters :accessor parameters :initarg :parameters :initform nil)
+   (prepared-name :accessor prepared-name :initarg :prepared-name :initform ""
+    :documentation "If we want this to be a prepared statement, give it a name
+       to identify it to this session")
+   (has-been-prepared :accessor has-been-prepared :initarg :has-been-prepared :initform nil
+                     :documentation "Have we already prepared this command object")
+   ))
+
+(defmethod initialize-instance :after ((o command-object) &key &allow-other-keys )
+  ;; Inits parameter nulls
+  (setf (parameters o) (parameters o)))
+
+(defmethod (setf parameters) (new (o command-object))
+  " This causes the semantics to match cl-sql instead of cl-postgresql
+  "
+  (setf (slot-value o 'parameters)
+       (loop for p in new
+             collecting (cond ((null p) :null)
+                              ((member p (list :false :F)) nil)
+                              (T p)))))
+
+(defun reset-command-object (co)
+  "Resets the command object to have no name and to be unprepared
+     (This is useful if you want to run a command against a second database)"
+  (setf (prepared-name co) ""
+       (has-been-prepared co) nil))
+
+(defun command-object (expression &optional parameters (prepared-name ""))
+  (make-instance 'command-object
+                :expression expression
+                :parameters parameters
+                :prepared-name prepared-name))
index 3a9fe7c20f0c25f60183c9881df40f1c899763f1..f922b18135132f5836021248e697860447ae3513 100644 (file)
      #:sql-escape
      #:in
 
+     ;; Command-object.lisp
+     #:expression
+     #:parameters
+     #:prepared-name
+     #:has-been-prepared
+     #:command-object
+     #:reset-command-object
+
      ;; Generic backends
      #:generic-postgresql-database
      #:generic-odbc-database