X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Fbasic-sql.lisp;fp=sql%2Fbasic-sql.lisp;h=2c61f253754b960a602094729af97edc1017f01f;hb=8a8ee2d7d791b7a3efaed06420802a925d16fca3;hp=0000000000000000000000000000000000000000;hpb=09f07ac9d914a83f9426609f3264f4e66b5a6d97;p=clsql.git diff --git a/sql/basic-sql.lisp b/sql/basic-sql.lisp new file mode 100644 index 0000000..2c61f25 --- /dev/null +++ b/sql/basic-sql.lisp @@ -0,0 +1,80 @@ +;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*- +;;;; ************************************************************************* +;;;; +;;;; $Id$ +;;;; +;;;; Base SQL functions +;;;; +;;;; 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-sys) + +;;; Query + +(defgeneric query (query-expression &key database result-types flatp) + (:documentation + "Execute the SQL query expression QUERY-EXPRESSION on the given +DATABASE which defaults to *default-database*. RESULT-TYPES is a list +of symbols such as :string and :integer, one for each field in the +query, which are used to specify the types to return. The FLATP +argument, which has a default value of nil, specifies if full +bracketed results should be returned for each matched entry. If FLATP +is nil, the results are returned as a list of lists. If FLATP is t, +the results are returned as elements of a list, only if there is only +one result per row. Returns a list of lists of values of the result of +that expression and a list of field names selected in sql-exp.")) + +(defmethod query ((query-expression string) &key (database *default-database*) + (result-types :auto) (flatp nil) (field-names t)) + (record-sql-command query-expression database) + (multiple-value-bind (rows names) (database-query query-expression database result-types + field-names) + (let ((result (if (and flatp (= 1 (length (car rows)))) + (mapcar #'car rows) + rows))) + (record-sql-result result database) + (if field-names + (values result names) + result)))) + +;;; Execute + +(defgeneric execute-command (expression &key database) + (:documentation + "Executes the SQL command specified by EXPRESSION for the database +specified by DATABASE, which has a default value of +*DEFAULT-DATABASE*. The argument EXPRESSION may be any SQL statement +other than a query. To run a stored procedure, pass an appropriate +string. The call to the procedure needs to be wrapped in a BEGIN END +pair.")) + +(defmethod execute-command ((sql-expression string) + &key (database *default-database*)) + (record-sql-command sql-expression database) + (let ((res (database-execute-command sql-expression database))) + (record-sql-result res database)) + (values)) + +;;; Large objects support + +(defun create-large-object (&key (database *default-database*)) + "Creates a new large object in the database and returns the object identifier" + (database-create-large-object database)) + +(defun write-large-object (object-id data &key (database *default-database*)) + "Writes data to the large object" + (database-write-large-object object-id data database)) + +(defun read-large-object (object-id &key (database *default-database*)) + "Reads the large object content" + (database-read-large-object object-id database)) + +(defun delete-large-object (object-id &key (database *default-database*)) + "Deletes the large object in the database" + (database-delete-large-object object-id database)) +