;;;; FILE IDENTIFICATION
;;;;
;;;; Name: clsql-postgresql-socket.asd
-;;;; Purpose: ASDF file for CLSQL PostgresSQL socket backend
-;;;; Programmer: Kevin M. Rosenberg
-;;;; Date Started: Aug 2002
+;;;; Purpose: ASDF file for CLSQL PostgresSQL socket (protocol vs 3) backend
+;;;; Programmer: Russ Tyndall
+;;;; Date Started: Sept 2009
;;;;
;;;; $Id$
;;;;
:components
((:module :db-postgresql-socket3
:serial T
- :components ((:file "package")
+ :components ((:file "command-object")
+ (:file "package")
(:file "api")
(:file "sql")))))
--- /dev/null
+;;;; -*- 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))
+
+
(apply #'values (cl-postgres:exec-query connection expression #'clsql-default-row-reader)))
)))
+(defmethod query ((obj command-object) &key (database *default-database*)
+ (result-types :auto) (flatp nil) (field-names t))
+ (clsql-sys::record-sql-command (expression obj) database)
+ (multiple-value-bind (rows names)
+ (database-query obj database result-types field-names)
+ (let ((result (if (and flatp (= 1 (length (car rows))))
+ (mapcar #'car rows)
+ rows)))
+ (clsql-sys::record-sql-result result database)
+ (if field-names
+ (values result names)
+ result))))
+
+(defmethod database-query ((obj command-object) (database postgresql-socket3-database) result-types field-names)
+ (let ((connection (database-connection database))
+ (cl-postgres:*sql-readtable* *sqlreader*))
+ (with-postgresql-handlers (database obj)
+ (let ((*include-field-names* field-names))
+ (unless (has-been-prepared obj)
+ (cl-postgres:prepare-query connection (prepared-name obj) (expression obj))
+ (setf (has-been-prepared obj) T))
+ (apply #'values (cl-postgres:exec-prepared
+ connection
+ (prepared-name obj)
+ (parameters obj)
+ #'clsql-default-row-reader))))))
+
(defmethod database-execute-command
((expression string) (database postgresql-socket3-database))
(let ((connection (database-connection database)))