+2010-02-07 Kevin Rosenberg <kevin@rosenberg.net>
+ * Version 5.0.1
+ * sql/{base-classes,database}.lisp: Add encoding slot for
+ non-ASCII strings.
+ * db-mysql/mysql-sql.lisp: Use UFFI:FOREIGN-ENCODED-OCTET-COUNT.
+ Requires UFFI version 1.8.2 or above.
+
2010-02-06 Kevin Rosenberg <kevin@rosenberg.net>
* Version 5.0.0: First release of CLSQL to formally and
consistently support non-ASCII strings with encoding of external
:mysql-ptr mysql-ptr))
(cmd "SET SESSION sql_mode='ANSI'"))
(uffi:with-cstring (cmd-cs cmd)
- (if (zerop (mysql-real-query mysql-ptr cmd-cs (uffi:foreign-encoded-string-octets cmd)))
+ (if (zerop (mysql-real-query mysql-ptr cmd-cs (uffi:foreign-encoded-octet-count
+ cmd :encoding (encoding db))))
db
(progn
(warn "Error setting ANSI mode for MySQL.")
(let ((mysql-ptr (database-mysql-ptr database)))
(declare (type mysql-mysql-ptr-def mysql-ptr))
(if (zerop (mysql-real-query mysql-ptr sql-native
- (uffi:foreign-encoded-string-octets sql-expression)))
+ (uffi:foreign-encoded-octet-count
+ sql-expression :encoding (encoding database))))
t
(error 'sql-database-data-error
:database database
:message (mysql-error-string mysql-ptr)))
(uffi:with-cstring (native-query sql-stmt)
- (unless (zerop (mysql-stmt-prepare stmt native-query (uffi:foreign-encoded-string-octets sql-stmt)))
+ (unless (zerop (mysql-stmt-prepare stmt native-query (uffi:foreign-encoded-octet-count
+ sql-stmt :encoding (encoding database))))
(mysql-stmt-close stmt)
(error 'sql-database-error
:error-id (mysql-errno mysql-ptr)
+cl-sql (5.0.1-1) unstable; urgency=low
+
+ * New upstream
+
+ -- Kevin M. Rosenberg <kmr@debian.org> Sun, 07 Feb 2010 22:34:13 -0700
+
cl-sql (5.0.0-1) unstable; urgency=low
* New upstream
;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
-;;;; Name: classes.lisp
-;;;; Purpose: Classes for High-level SQL interface
+;;;; Name: base-classes.lisp
+;;;; Purpose: Base classes for high-level SQL interface
;;;; Programmers: Kevin M. Rosenberg based on
;;;; original code by Pierre R. Mai
;;;; Date Started: Feb 2002
((name :initform nil :initarg :name :reader database-name)
(connection-spec :initform nil :initarg :connection-spec
:reader connection-spec
- :documentation "Require to use connection pool")
+ :documentation "Required to use connection pool.")
(database-type :initarg :database-type :initform :unknown
:reader database-type)
+ (encoding :initarg :encoding :initform nil
+ :documentation "External format character encoding.")
(state :initform :closed :reader database-state)
(autocommit :initform t :accessor database-autocommit)
(command-recording-stream :accessor command-recording-stream :initform nil)
&key (if-exists *connect-if-exists*)
(make-default t)
(pool nil)
- (database-type *default-database-type*))
+ (database-type *default-database-type*)
+ (encoding nil))
"Connects to a database of the supplied DATABASE-TYPE which
defaults to *DEFAULT-DATABASE-TYPE*, using the type-specific
connection specification CONNECTION-SPEC. The value of IF-EXISTS,
(setf (slot-value result 'state) :open)
(pushnew result *connected-databases*)
(when make-default (setq *default-database* result))
+ (setf (encoding result) encoding)
result))))
(setq connection-spec (string-to-list-connection-spec connection-spec)))
(database-list connection-spec database-type))
+(defun encoding (db)
+ (when (typep db 'database)
+ (slot-value db 'encoding)))
+
+(defun (setf encoding) (encoding db)
+ (when (typep db 'database)
+ (setf (slot-value db 'encoding) encoding)
+ (when (eql (slot-value db 'state) :open)
+ (case database-type
+ ;; FIXME: If database object is open then
+ ;; send command to SQL engine specifying the character
+ ;; encoding for the database
+ (:mysql
+ )
+ ((:postgresql :postgresql-socket)
+ )))))
+
(defmacro with-database ((db-var connection-spec
&key make-default pool
(if-exists *connect-if-exists*)
- (database-type *default-database-type*))
+ (database-type *default-database-type*)
+ (encoding nil))
&body body)
"Evaluate the body in an environment, where DB-VAR is bound to the
database connection given by CONNECTION-SPEC and CONNECT-ARGS. The
:database-type ,database-type
:if-exists ,if-exists
:pool ,pool
- :make-default ,make-default)))
+ :make-default ,make-default
+ :encoding ,encoding)))
(unwind-protect
(let ((,db-var ,db-var))
(progn ,@body))
`(progv '(*default-database*)
(list ,database)
,@body))
-
#:database-state
#:attribute-cache
#:database-autocommit
+ #:encoding
;; utils.lisp
#:without-interrupts