(if (or (not errorp) (= count 1))
(values (car matches) count)
(cerror "Return nil."
- 'clsql-simple-error
- :format-control "There exists ~A database called ~A."
- :format-arguments
- (list (if (zerop count) "no" "more than one")
- database)))))))
+ 'sql-database-error
+ :message
+ (format nil "There exists ~A database called ~A."
+ (if (zerop count) "no" "more than one")
+ database)))))))
(defun connect (connection-spec
is a conn-pool object the connection will be taken from this pool."
(unless database-type
- (error "Must specify a database-type."))
+ (error 'sql-database-error :message "Must specify a database-type."))
(when (stringp connection-spec)
(setq connection-spec (string-to-list-connection-spec connection-spec)))
(:warn-new
(setq result
(database-connect connection-spec database-type))
- (warn 'clsql-exists-warning :old-db old-db :new-db result))
- (:error
+ (warn 'sql-warning
+ :message
+ (format nil
+ "Created new connection ~A to database ~A~%, although there is an existing connection (~A)."
+ result (database-name result) old-db)))
+ (:error
(restart-case
- (error 'clsql-exists-error :old-db old-db)
+ (error 'sql-connection-error
+ :message
+ "There is an existing connection ~A to database ~A."
+ old-db
+ (database-name old-db))
(create-new ()
:report "Create a new connection."
(setq result
(setq result old-db))))
(:warn-old
(setq result old-db)
- (warn 'clsql-exists-warning :old-db old-db :new-db old-db))
+ (warn 'sql-warning
+ :message
+ (format nil
+ "Using existing connection ~A to database ~A."
+ old-db
+ (database-name old-db))))
(:old
(setq result old-db)))
(setq result
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
+(defmacro check-connection-spec (connection-spec database-type template)
+ "Check the connection specification against the provided template,
+and signal an sql-user-error if they don't match. This function
+is called by database backends."
+ `(handler-case
+ (destructuring-bind ,template ,connection-spec
+ (declare (ignore ,@(remove '&optional template)))
+ t)
+ (error ()
+ (error 'sql-user-error
+ :message
+ (format nil
+ "The connection specification ~A~%is invalid for database type ~A.~%The connection specification must conform to ~A"
+ ,connection-spec
+ ,database-type
+ (quote ,template))))))
(defun reconnect (&key (database *default-database*) (error nil) (force t))
"Reconnects DATABASE to its underlying RDBMS. If successful, returns