BLOBs

"Paul Werkowski" <[email protected]>
Newsgroups gmane.lisp.clsql.devel
Message-ID <000501c4da1b$a1dd65f0$0201a8c0@moby>
Here is some code that lets one create a :mysql or :sqlite3 table with BLOB
datatypes.
For example
(clsql:create-table "foo" '((a clsql:long-blob)))

Also, for :mysql, the default :result-types of :auto will cause a vector of
(unsigned-byte 8)
to be returned for any BLOB field. I did not attempt to make a diff file
because I'm not
sure how you might want to integrate this into the system. I just load this
file for now.

Paul


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;; Additional support for mysql blob types
;;;
(in-package :clsql-sys)
(export '(blob tiny-blob medium-blob long-blob))
(import '(blob tiny-blob medium-blob long-blob) :clsql)

(in-package #:clsql-mysql)
;; file mysql-objects.lisp
(defmethod database-get-type-specifier
           ((type (eql 'blob)) args database (db-type (eql :mysql)))
  (declare (ignore args database db-type))
  "BLOB")


(defmethod database-get-type-specifier
           ((type (eql 'tiny-blob)) args database (db-type (eql :mysql)))
  (declare (ignore args database db-type))
  "TINYBLOB")


(defmethod database-get-type-specifier
           ((type (eql 'medium-blob)) args database (db-type (eql :mysql)))
  (declare (ignore args database db-type))
  "MEDIUMBLOB")

(defmethod database-get-type-specifier
           ((type (eql 'long-blob)) args database (db-type (eql :mysql)))
  (declare (ignore args database db-type))
  "LONGBLOB")


;;; file mysql-sql.lisp
(defun make-type-list-for-auto (num-fields res-ptr)
  (declare (fixnum num-fields))
  (let ((new-types '())
        (field-vec (mysql-fetch-fields res-ptr)))
    (dotimes (i num-fields)
      (declare (fixnum i))
      (let* ((field (uffi:deref-array field-vec '(:array mysql-field) i))
      (type (uffi:get-slot-value field 'mysql-field 'type)))
 (push
  (case type
    ((#.mysql-field-types#tiny
      #.mysql-field-types#short
      #.mysql-field-types#int24
      #.mysql-field-types#long)
     :int32)
    (#.mysql-field-types#longlong
     :int64)
    ((#.mysql-field-types#double
      #.mysql-field-types#float
      #.mysql-field-types#decimal)
     :double)
           ((#.mysql-field-types#blob
             #.mysql-field-types#tiny-blob
             #.mysql-field-types#long-blob
             #.mysql-field-types#medium-blob)
            :blob)
    (otherwise
     t))
  new-types)))
    (nreverse new-types)))

(in-package #:clsql-sqlite3)
(defmethod database-get-type-specifier
           ((type (eql 'blob)) args database (db-type (eql :sqlite3)))
  (declare (ignore args database db-type))
  "BLOB")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.