X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Fclasses.lisp;h=558127ae9bbd28d18e34d702bad90acac53d8a15;hb=f2a0eb003af406415567c9f8545455ede786db87;hp=8f75cbf7a1c91f6ceb49244487cb68d7e1bf6e4d;hpb=73cf858d596ad1d51c745b478292433617cf9d72;p=clsql.git diff --git a/sql/classes.lisp b/sql/classes.lisp index 8f75cbf..558127a 100644 --- a/sql/classes.lisp +++ b/sql/classes.lisp @@ -22,14 +22,6 @@ (defvar *sql-stream* nil "stream which accumulates SQL output") -(defvar *default-schema* "UNCOMMONSQL") - -(defvar *object-schemas* (make-hash-table :test #'equal) - "Hash of schema name to class constituent lists.") - -(defun in-schema (schemaname) - (setf *default-schema* schemaname)) - (defun sql-output (sql-expr &optional database) (progv '(*sql-stream*) `(,(make-string-output-stream)) @@ -202,6 +194,16 @@ (format *sql-stream* "~s" alias)))) t) +#| +(defmethod database-output-sql ((self duration) database) + (declare (ignore database)) + (format nil "'~a'" (duration-timestring self))) + +(defmethod database-output-sql ((self money) database) + (database-output-sql (slot-value self 'odcl::units) database)) +|# + + (defmethod output-sql-hash-key ((expr sql-ident-table) &optional (database *default-database*)) (declare (ignore database)) @@ -628,6 +630,9 @@ uninclusive, and the args from that keyword to the end." :initform nil) (modifiers :initarg :modifiers + :initform nil) + (transactions + :initarg :transactions :initform nil)) (:documentation "An SQL CREATE TABLE statement.")) @@ -642,20 +647,21 @@ uninclusive, and the args from that keyword to the end." (defmethod output-sql ((stmt sql-create-table) &optional (database *default-database*)) (flet ((output-column (column-spec) - (destructuring-bind (name type &rest constraints) + (destructuring-bind (name type &optional db-type &rest constraints) column-spec (let ((type (listify type))) (output-sql name database) (write-char #\Space *sql-stream*) (write-string - (database-get-type-specifier (car type) (cdr type) database) + (if (stringp db-type) db-type ; override definition + (database-get-type-specifier (car type) (cdr type) database)) *sql-stream*) (let ((constraints (database-constraint-statement constraints database))) (when constraints (write-string " " *sql-stream*) (write-string constraints *sql-stream*))))))) - (with-slots (name columns modifiers) + (with-slots (name columns modifiers transactions) stmt (write-string "CREATE TABLE " *sql-stream*) (output-sql name database) @@ -670,7 +676,11 @@ uninclusive, and the args from that keyword to the end." ((null modifier)) (write-string ", " *sql-stream*) (write-string (car modifier) *sql-stream*))) - (write-char #\) *sql-stream*))) + (write-char #\) *sql-stream*) + (when (and (eq :mysql (database-underlying-type database)) + transactions + (db-type-transaction-capable? :mysql database)) + (write-string " Type=InnoDB" *sql-stream*)))) t)