From: Russ Tyndall Date: Wed, 8 Jun 2011 21:05:47 +0000 (-0400) Subject: improved and moved command object up to clsql (out of cl-postgres-socket3) X-Git-Tag: v6.0.0~4^2~29 X-Git-Url: http://git.kpe.io/?p=clsql.git;a=commitdiff_plain;h=b49459599b33655a541817d317dfeb6f839f637e;ds=sidebyside improved and moved command object up to clsql (out of cl-postgres-socket3) * 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 --- diff --git a/clsql-postgresql-socket3.asd b/clsql-postgresql-socket3.asd index 901057a..4f4bd25 100644 --- a/clsql-postgresql-socket3.asd +++ b/clsql-postgresql-socket3.asd @@ -33,7 +33,6 @@ :components ((:module :db-postgresql-socket3 :serial T - :components ((:file "command-object") - (:file "package") + :components ((:file "package") (:file "api") (:file "sql"))))) diff --git a/clsql.asd b/clsql.asd index 7c97005..9366281 100644 --- 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 index 47dad33..0000000 --- a/db-postgresql-socket3/command-object.lisp +++ /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 index 0000000..3b752ef --- /dev/null +++ b/sql/command-object.lisp @@ -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)) diff --git a/sql/package.lisp b/sql/package.lisp index 3a9fe7c..f922b18 100644 --- a/sql/package.lisp +++ b/sql/package.lisp @@ -210,6 +210,14 @@ #: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