From: Kevin M. Rosenberg Date: Sun, 11 Apr 2004 01:34:00 +0000 (+0000) Subject: r8930: add database-create for pg socket, documentation improvements X-Git-Tag: v3.8.6~683 X-Git-Url: http://git.kpe.io/?p=clsql.git;a=commitdiff_plain;h=72c5d9d0555b01290409dc2607935db823fa1f10 r8930: add database-create for pg socket, documentation improvements --- diff --git a/ChangeLog b/ChangeLog index e4f8290..248570e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,8 +6,9 @@ * base/conditions.lisp: Added CLSQL-ACCESS-ERROR * base/utils.lisp: Fix use of position-char. Add COMMAND-OUTPUT used by backends for running - shell commands. - * base/loop-extension.lisp: Rework packages + external programs. Fix parsing of SQL*NET-compatible + connection-specs. + * base/loop-extension.lisp: Simplify package use for Lispworks and Allegro * db-*/*-sql.lisp: Added DATABASE-CREATE, DATABASE-DESTORY, PROBE-DATABASE methods @@ -16,6 +17,14 @@ testing with empty database * tests/test-connection.lisp: Add tests for parsing of string connection-specs + * examples/run-tests.sh: New file for running + test suite on all installed CL implementations + * examples/clsql-tutorial.lisp: moved from + doc directory + * examples/dot.clsql-tests.config: New file + giving an example test configuration + * test/README: Add notes about rtest/ptester + downloads and link to sample test configuration file. 10 Apr 2004 Kevin Rosenberg (kevin@rosenberg.net) * Version 2.5.1 released: diff --git a/classic-tests/README b/classic-tests/README index 3e1b561..4fb0437 100644 --- a/classic-tests/README +++ b/classic-tests/README @@ -1,20 +1,8 @@ -These tests require the setup of a configuration file with account -information for MySQL and PostgreSQL SQL servers. Additionally, the -Debian package acl-installer must be installed and a license -downloaded to use the AODBC tests. - -Furthermore, if you are not using the Debian package of CLSQL, these -tests require the downloading of the rtest and ptester packages from -http://files.b9.com/. - This test suite looks for a configuration file named -".clsql-test.config" located in the users home directory. - -This file contains a single a-list that specifies the connection - specs for each database type to be tested. For example, to test all -platforms, a sample file might look like this: +".clsql-test.config" located in the users home directory. This file +contains a single assoc-list that specifies the connection specs for +each database type to be tested. There is an example file in contained +in CLSQL's examples directory. -((:mysql ("localhost" "a-mysql-db" "user1" "secret")) - (:aodbc ("my-dsn" "a-user" "pass")) - (:postgresql ("localhost" "another-db" "user2" "dont-tell")) - (:postgresql-socket ("pg-server" "a-db-name" "user" "secret-password"))) +These tests require the downloading of the rtest and ptester packages +from http://files.b9.com/. diff --git a/clsql-tests.asd b/clsql-tests.asd index 274e69b..b4cbdb9 100644 --- a/clsql-tests.asd +++ b/clsql-tests.asd @@ -7,13 +7,12 @@ ;;;; Created: 30/03/2004 ;;;; Updated: $Id$ ;;;; -;;;; $Id$ +;;;; This file is part of CLSQL. ;;;; ;;;; 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 #:cl-user) (defpackage #:clsql-tests-system (:use #:asdf #:cl)) diff --git a/db-postgresql-socket/postgresql-socket-sql.lisp b/db-postgresql-socket/postgresql-socket-sql.lisp index 9a2f02d..c304db0 100644 --- a/db-postgresql-socket/postgresql-socket-sql.lisp +++ b/db-postgresql-socket/postgresql-socket-sql.lisp @@ -430,16 +430,20 @@ doesn't depend on UFFI." (defmethod database-create (connection-spec (type (eql :postgresql-socket))) - (error 'clsql-access-error - :connection-spec connection-spec - :database-type type - :error "Unable to create databases on a socket connection.")) + (destructuring-bind (host name user password) connection-spec + (let ((database (database-connect (list host "template1" user password) + type))) + (unwind-protect + (execute-command (format nil "create database ~A" name)) + (database-disconnect database))))) (defmethod database-destroy (connection-spec (type (eql :postgresql-socket))) - (error 'clsql-access-error - :connection-spec connection-spec - :database-type type - :error "Unable to create databases on a socket connection.")) + (destructuring-bind (host name user password) connection-spec + (let ((database (database-connect (list host "template1" user password) + type))) + (unwind-protect + (execute-command (format nil "drop database ~A" name)) + (database-disconnect database))))) (defmethod database-probe (connection-spec (type (eql :postgresql-socket))) (destructuring-bind (host name user password) connection-spec diff --git a/debian/rules b/debian/rules index 81bb0af..ac7c764 100755 --- a/debian/rules +++ b/debian/rules @@ -189,7 +189,7 @@ binary-indep: build install dh_testroot -i # dh_installdebconf -i dh_installdocs -i - dh_installexamples -i + dh_installexamples -i examples dh_installmenu -i # dh_installlogrotate -i # dh_installemacsen -i diff --git a/doc/clsql-tutorial.lisp b/doc/clsql-tutorial.lisp deleted file mode 100644 index 2afb0f8..0000000 --- a/doc/clsql-tutorial.lisp +++ /dev/null @@ -1,191 +0,0 @@ -(asdf:operate 'asdf:load-op 'clsql) - -(in-package #:clsql-user) - -;; You must set these variables to appropriate values. -(defvar *tutorial-database-type* nil - "Possible values are :postgresql,:postgresql-socket :mysql or :sqlite") -(defvar *tutorial-database-name* "" - "The name of the database we will work in.") -(defvar *tutorial-database-user* "" - "The name of the database user we will work as.") -(defvar *tutorial-database-server* "" - "The name of the database server if required") -(defvar *tutorial-database-password* "" - "The password if required") - -(clsql:def-view-class employee () - ((emplid - :db-kind :key - :db-constraints :not-null - :nulls-ok nil - :type integer - :initarg :emplid) - (first-name - :accessor first-name - :type (string 30) - :initarg :first-name) - (last-name - :accessor last-name - :type (string 30) - :initarg :last-name) - (email - :accessor employee-email - :type (string 100) - :nulls-ok t - :initarg :email) - (companyid - :type integer) - (company - :accessor employee-company - :db-kind :join - :db-info (:join-class company - :home-key companyid - :foreign-key companyid - :set nil)) - (managerid - :type integer - :nulls-ok t) - (manager - :accessor employee-manager - :db-kind :join - :db-info (:join-class employee - :home-key managerid - :foreign-key emplid - :set nil))) - (:base-table employee)) - -(clsql:def-view-class company () - ((companyid - :db-type :key - :db-constraints :not-null - :type integer - :initarg :companyid) - (name - :type (string 100) - :initarg :name) - (presidentid - :type integer) - (president - :reader president - :db-kind :join - :db-info (:join-class employee - :home-key presidentid - :foreign-key emplid - :set nil)) - (employees - :reader company-employees - :db-kind :join - :db-info (:join-class employee - :home-key companyid - :foreign-key companyid - :set t))) - (:base-table company)) - -;; Connect to the database (see the CLSQL documentation for vendor -;; specific connection specs). -(clsql:connect `(,*tutorial-database-server* - ,*tutorial-database-name* - ,*tutorial-database-user* - ,*tutorial-database-password*) - :database-type *tutorial-database-type*) - -;; Record the sql going out, helps us learn what is going -;; on behind the scenes -(clsql:start-sql-recording) - -;; Create the tables for our view classes -;; First we drop them, ignoring any errors -(ignore-errors - (clsql:drop-view-from-class 'employee) - (clsql:drop-view-from-class 'company)) - -(clsql:create-view-from-class 'employee) -(clsql:create-view-from-class 'company) - - -;; Create some instances of our view classes -(defvar employee1 (make-instance 'employee - :emplid 1 - :first-name "Vladamir" - :last-name "Lenin" - :email "lenin@soviet.org")) - -(defvar company1 (make-instance 'company - :companyid 1 - :name "Widgets Inc.")) - - -(defvar employee2 (make-instance 'employee - :emplid 2 - :first-name "Josef" - :last-name "Stalin" - :email "stalin@soviet.org")) - -;; Lenin manages Stalin (for now) -(clsql:add-to-relation employee2 'manager employee1) - -;; Lenin and Stalin both work for Widgets Inc. -(clsql:add-to-relation company1 'employees employee1) -(clsql:add-to-relation company1 'employees employee2) - -;; Lenin is president of Widgets Inc. -(clsql:add-to-relation company1 'president employee1) - -(clsql:update-records-from-instance employee1) -(clsql:update-records-from-instance employee2) -(clsql:update-records-from-instance company1) - -;; lets us use the functional -;; sql interface -(clsql:locally-enable-sql-reader-syntax) - - -(format t "The email address of ~A ~A is ~A" - (first-name employee1) - (last-name employee1) - (employee-email employee1)) - -(setf (employee-email employee1) "lenin-nospam@soviets.org") - -;; Update the database -(clsql:update-records-from-instance employee1) - -(let ((new-lenin (car - (clsql:select 'employee - :where [= [slot-value 'employee 'emplid] 1])))) - (format t "His new email is ~A" - (employee-email new-lenin))) - - -;; Some queries - -;; all employees -(clsql:select 'employee) -;; all companies -(clsql:select 'company) - -;; employees named Lenin -(clsql:select 'employee :where [= [slot-value 'employee 'last-name] - "Lenin"]) - -(clsql:select 'company :where [= [slot-value 'company 'name] - "Widgets Inc."]) - -;; Employees of Widget's Inc. -(clsql:select 'employee - :where [and [= [slot-value 'employee 'companyid] - [slot-value 'company 'companyid]] - [= [slot-value 'company 'name] - "Widgets Inc."]]) - -;; Same thing, except that we are using the employee -;; relation in the company view class to do the join for us, -;; saving us the work of writing out the SQL! -(company-employees company1) - -;; President of Widgets Inc. -(president company1) - -;; Manager of Josef Stalin -(employee-manager employee2) diff --git a/examples/clsql-tutorial.lisp b/examples/clsql-tutorial.lisp new file mode 100644 index 0000000..2afb0f8 --- /dev/null +++ b/examples/clsql-tutorial.lisp @@ -0,0 +1,191 @@ +(asdf:operate 'asdf:load-op 'clsql) + +(in-package #:clsql-user) + +;; You must set these variables to appropriate values. +(defvar *tutorial-database-type* nil + "Possible values are :postgresql,:postgresql-socket :mysql or :sqlite") +(defvar *tutorial-database-name* "" + "The name of the database we will work in.") +(defvar *tutorial-database-user* "" + "The name of the database user we will work as.") +(defvar *tutorial-database-server* "" + "The name of the database server if required") +(defvar *tutorial-database-password* "" + "The password if required") + +(clsql:def-view-class employee () + ((emplid + :db-kind :key + :db-constraints :not-null + :nulls-ok nil + :type integer + :initarg :emplid) + (first-name + :accessor first-name + :type (string 30) + :initarg :first-name) + (last-name + :accessor last-name + :type (string 30) + :initarg :last-name) + (email + :accessor employee-email + :type (string 100) + :nulls-ok t + :initarg :email) + (companyid + :type integer) + (company + :accessor employee-company + :db-kind :join + :db-info (:join-class company + :home-key companyid + :foreign-key companyid + :set nil)) + (managerid + :type integer + :nulls-ok t) + (manager + :accessor employee-manager + :db-kind :join + :db-info (:join-class employee + :home-key managerid + :foreign-key emplid + :set nil))) + (:base-table employee)) + +(clsql:def-view-class company () + ((companyid + :db-type :key + :db-constraints :not-null + :type integer + :initarg :companyid) + (name + :type (string 100) + :initarg :name) + (presidentid + :type integer) + (president + :reader president + :db-kind :join + :db-info (:join-class employee + :home-key presidentid + :foreign-key emplid + :set nil)) + (employees + :reader company-employees + :db-kind :join + :db-info (:join-class employee + :home-key companyid + :foreign-key companyid + :set t))) + (:base-table company)) + +;; Connect to the database (see the CLSQL documentation for vendor +;; specific connection specs). +(clsql:connect `(,*tutorial-database-server* + ,*tutorial-database-name* + ,*tutorial-database-user* + ,*tutorial-database-password*) + :database-type *tutorial-database-type*) + +;; Record the sql going out, helps us learn what is going +;; on behind the scenes +(clsql:start-sql-recording) + +;; Create the tables for our view classes +;; First we drop them, ignoring any errors +(ignore-errors + (clsql:drop-view-from-class 'employee) + (clsql:drop-view-from-class 'company)) + +(clsql:create-view-from-class 'employee) +(clsql:create-view-from-class 'company) + + +;; Create some instances of our view classes +(defvar employee1 (make-instance 'employee + :emplid 1 + :first-name "Vladamir" + :last-name "Lenin" + :email "lenin@soviet.org")) + +(defvar company1 (make-instance 'company + :companyid 1 + :name "Widgets Inc.")) + + +(defvar employee2 (make-instance 'employee + :emplid 2 + :first-name "Josef" + :last-name "Stalin" + :email "stalin@soviet.org")) + +;; Lenin manages Stalin (for now) +(clsql:add-to-relation employee2 'manager employee1) + +;; Lenin and Stalin both work for Widgets Inc. +(clsql:add-to-relation company1 'employees employee1) +(clsql:add-to-relation company1 'employees employee2) + +;; Lenin is president of Widgets Inc. +(clsql:add-to-relation company1 'president employee1) + +(clsql:update-records-from-instance employee1) +(clsql:update-records-from-instance employee2) +(clsql:update-records-from-instance company1) + +;; lets us use the functional +;; sql interface +(clsql:locally-enable-sql-reader-syntax) + + +(format t "The email address of ~A ~A is ~A" + (first-name employee1) + (last-name employee1) + (employee-email employee1)) + +(setf (employee-email employee1) "lenin-nospam@soviets.org") + +;; Update the database +(clsql:update-records-from-instance employee1) + +(let ((new-lenin (car + (clsql:select 'employee + :where [= [slot-value 'employee 'emplid] 1])))) + (format t "His new email is ~A" + (employee-email new-lenin))) + + +;; Some queries + +;; all employees +(clsql:select 'employee) +;; all companies +(clsql:select 'company) + +;; employees named Lenin +(clsql:select 'employee :where [= [slot-value 'employee 'last-name] + "Lenin"]) + +(clsql:select 'company :where [= [slot-value 'company 'name] + "Widgets Inc."]) + +;; Employees of Widget's Inc. +(clsql:select 'employee + :where [and [= [slot-value 'employee 'companyid] + [slot-value 'company 'companyid]] + [= [slot-value 'company 'name] + "Widgets Inc."]]) + +;; Same thing, except that we are using the employee +;; relation in the company view class to do the join for us, +;; saving us the work of writing out the SQL! +(company-employees company1) + +;; President of Widgets Inc. +(president company1) + +;; Manager of Josef Stalin +(employee-manager employee2) diff --git a/examples/dot.clsql-test.config b/examples/dot.clsql-test.config new file mode 100644 index 0000000..c6308a1 --- /dev/null +++ b/examples/dot.clsql-test.config @@ -0,0 +1,14 @@ +;; -*- Mode: Lisp -*- ;; Emacs mode line +;; +;; Example CLSQL test configuration file +;; Since this file is read by Lisp, it is okay to use +;; comments in this file +;; This file should be named .clsql-test.config and +;; placed in your home directory + +((:mysql ("localhost" "a-mysql-db" "user1" "secret")) + (:aodbc ("my-dsn" "a-user" "pass")) + (:postgresql ("localhost" "another-db" "user2" "dont-tell")) + (:postgresql-socket ("pg-server" "a-db-name" "user" "secret-password")) + (:sqlite ("path-to-sqlite-db"))) + diff --git a/examples/run-tests.sh b/examples/run-tests.sh new file mode 100755 index 0000000..83a2fc4 --- /dev/null +++ b/examples/run-tests.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# Run CLSQL tests on all installed CL implementations +# Need to setup ~/.clsql-tests.config as show in +# tests/test-init.lisp + +CMD='(asdf:operate (quote asdf:test-op) :clsql-classic) + (asdf:operate (quote asdf:test-op) :clsql) + #+allegro (excl:exit :quiet t) + #+clisp (#+lisp=cl ext:quit #-lisp=cl lisp:quit) + #+cmu (ext:quit) + #+lispworks (lw:quit) + #+openmcl (ccl:quit) + #+sbcl (sb-ext:quit)) + #+scl (ext:quit)' + + + +ALLEGRO=alisp +if [ "`which $ALLEGRO`" ]; then + echo "$CMD" | $ALLEGRO +fi + +CMUCL=lisp +if [ "`which $CMUCL`" ]; then + echo "$CMD" | $CMUCL +fi + +LISPWORKS=lw-console +#LISPWORKS=lispworks-4300 +if [ "`which $LISPWORKS`" ]; then + echo "$CMD" | $LISPWORKS +fi + +OPENCML=openmcl +if [ "`which $OPENMCL`" ]; then + echo "$CMD" | $OPENMCL +fi + +SBCL=sbcl +if [ "`which $SBCL`" ]; then + echo "$CMD" | $SBCL +fi diff --git a/tests/README b/tests/README index f93cfa9..aa5bae1 100644 --- a/tests/README +++ b/tests/README @@ -1,7 +1,13 @@ * RUNNING THE REGRESSION SUITE -Create a .clsql-tests.config file in your home directory. -See test-init.lisp for the structure of the data. +This test suite looks for a configuration file named +".clsql-test.config" located in the users home directory. This file +contains a single assoc-list that specifies the connection specs for +each database type to be tested. There is an example file in +contained in CLSQL's examples directory. + +These tests require the downloading of the rtest and ptester packages +from http://files.b9.com/. Load clsql.asd or put it somewhere where ASDF can find it and call: diff --git a/tests/test-connection.lisp b/tests/test-connection.lisp index df91957..f35261e 100644 --- a/tests/test-connection.lisp +++ b/tests/test-connection.lisp @@ -4,13 +4,14 @@ ;;;; Authors: Marcus Pearce , Kevin Rosenberg ;;;; Created: 30/03/2004 ;;;; Updated: $Id$ -;;;; ====================================================================== -;;;; -;;;; Description ========================================================== -;;;; ====================================================================== ;;;; ;;;; Tests for CLSQL database connections. ;;;; +;;;; This file is part of CLSQL. +;;;; +;;;; 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-tests) diff --git a/tests/test-fddl.lisp b/tests/test-fddl.lisp index 918c56f..53fd5c7 100644 --- a/tests/test-fddl.lisp +++ b/tests/test-fddl.lisp @@ -4,14 +4,15 @@ ;;;; Author: Marcus Pearce ;;;; Created: 30/03/2004 ;;;; Updated: $Id$ -;;;; ====================================================================== -;;;; -;;;; Description ========================================================== -;;;; ====================================================================== ;;;; ;;;; Tests for the CLSQL Functional Data Definition Language ;;;; (FDDL). -;;;; +;;;; +;;;; This file is part of CLSQL. +;;;; +;;;; 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-tests) diff --git a/tests/test-fdml.lisp b/tests/test-fdml.lisp index ef364ba..1e2a92b 100644 --- a/tests/test-fdml.lisp +++ b/tests/test-fdml.lisp @@ -4,14 +4,15 @@ ;;;; Author: Marcus Pearce ;;;; Created: 30/03/2004 ;;;; Updated: $Id$ -;;;; ====================================================================== -;;;; -;;;; Description ========================================================== -;;;; ====================================================================== ;;;; ;;;; Tests for the CLSQL Functional Data Manipulation Language ;;;; (FDML). -;;;; +;;;; +;;;; This file is part of CLSQL. +;;;; +;;;; 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-tests) diff --git a/tests/test-init.lisp b/tests/test-init.lisp index 005c247..1a274d9 100644 --- a/tests/test-init.lisp +++ b/tests/test-init.lisp @@ -4,28 +4,11 @@ ;;;; Authors: Marcus Pearce , Kevin Rosenberg ;;;; Created: 30/03/2004 ;;;; Updated: $Id$ -;;;; ====================================================================== -;;;; -;;;; Description ========================================================== -;;;; ====================================================================== ;;;; ;;;; Initialisation utilities for running regression tests on CLSQL. ;;;; ;;;; ====================================================================== -;;; This test suite looks for a configuration file named ".clsql-test.config" -;;; located in the users home directory. -;;; -;;; This file contains a single a-list that specifies the connection -;;; specs for each database type to be tested. For example, to test all -;;; platforms, a sample "test.config" may look like: -;;; -;;; ((:mysql ("localhost" "a-mysql-db" "user1" "secret")) -;;; (:aodbc ("my-dsn" "a-user" "pass")) -;;; (:postgresql ("localhost" "another-db" "user2" "dont-tell")) -;;; (:postgresql-socket ("pg-server" "a-db-name" "user" "secret-password")) -;;; (:sqlite ("path-to-sqlite-db"))) - (in-package #:clsql-tests) (defvar *rt-connection*) diff --git a/tests/test-ooddl.lisp b/tests/test-ooddl.lisp index 7089eba..9883b7a 100644 --- a/tests/test-ooddl.lisp +++ b/tests/test-ooddl.lisp @@ -4,14 +4,15 @@ ;;;; Author: Marcus Pearce ;;;; Created: 30/03/2004 ;;;; Updated: $Id$ -;;;; ====================================================================== -;;;; -;;;; Description ========================================================== -;;;; ====================================================================== ;;;; ;;;; Tests for the CLSQL Object Oriented Data Definition Language ;;;; (OODDL). ;;;; +;;;; This file is part of CLSQL. +;;;; +;;;; 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. ;;;; ====================================================================== diff --git a/tests/test-oodml.lisp b/tests/test-oodml.lisp index cf9eda7..c586726 100644 --- a/tests/test-oodml.lisp +++ b/tests/test-oodml.lisp @@ -4,14 +4,15 @@ ;;;; Author: Marcus Pearce ;;;; Created: 01/04/2004 ;;;; Updated: $Id$ -;;;; ====================================================================== -;;;; -;;;; Description ========================================================== -;;;; ====================================================================== ;;;; ;;;; Tests for the CLSQL Object Oriented Data Definition Language ;;;; (OODML). ;;;; +;;;; This file is part of CLSQL. +;;;; +;;;; 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-tests)