[elephant-cvs] CVS elephant/src/db-clsql

rread rread at common-lisp.net
Wed Feb 14 22:39:10 UTC 2007


Update of /project/elephant/cvsroot/elephant/src/db-clsql
In directory clnet:/tmp/cvs-serv3373

Modified Files:
	sql-controller.lisp 
Log Message:
Changes to make sqlite3 work


--- /project/elephant/cvsroot/elephant/src/db-clsql/sql-controller.lisp	2007/02/08 22:33:35	1.18
+++ /project/elephant/cvsroot/elephant/src/db-clsql/sql-controller.lisp	2007/02/14 22:39:10	1.19
@@ -41,6 +41,13 @@
     creation, counters, locks, the root (for garbage collection,)
     et cetera.  This is the Postgresql-specific subclass of store-controller."))
 
+(defmethod supports-sequence ((sc sql-store-controller))
+  (not (equal 
+	(car (cadr (controller-spec sc)))
+	:sqlite3)
+       )
+)
+
 ;; This should be much more elegant --- but as of Feb. 6, SBCL 1.0.2 has a weird,
 ;; unpleasant bug when ASDF tries to load this stuff.
 ;; (defvar *thread-table-lock* nil)
@@ -52,13 +59,13 @@
   (if (null *thread-table-lock*)
 ;;      nil
 ;;  (setq *thread-table-lock* (sb-thread::make-mutex :name "thread-table-lock"))
-      (setq *thread-table-lock* (elephant::ele-make-lock))
+      (setq *thread-table-lock* (elephant-utils::ele-make-lock))
       )
 )
 
 
 (defun thread-hash ()
-  (elephant::ele-thread-hash-key)
+  (elephant-utils::ele-thread-hash-key)
 )
 
 
@@ -284,14 +291,26 @@
   (clsql:table-exists-p [version] :database con :owner :all)
   )
 
-(defun create-version-table (con)
-  ;; ALL OF THIS needs to be inside a transaction.
-  (clsql::create-table [version]
+(defun create-version-table (sc)
+  (let ((con (controller-db sc)))
+    (clsql::create-table [version]
 		       '(
 			 ([dbversion] text :not-null)
 			 ) :database con
 		       )
-  )
+   (if (and (clsql:table-exists-p [keyvlaue] :database con :owner :all)
+	    (= 0 (caar (clsql:query "select count(*) from keyvalue"))))
+	  (clsql::insert-records :into [version]
+				 :attributes '(dbversion)
+				 :values (list (format nil "~A" *elephant-code-version*))
+				 :database con)
+	  (clsql::insert-records :into [version]
+				 :attributes '(dbversion)
+				 :values (list (format nil "~A" '(0 6 0)))
+				 :database con)
+	  )
+      )
+    )
 
 ;; These functions are probably not cross-database portable...
 (defun keyvalue-table-exists (con)
@@ -320,7 +339,7 @@
 ;; storing blobs now in the Berkeley-db and we meed to make sure 
 ;; we are properly testing that.  However, blobs are awkward to 
 ;; handle, so I am going to do this first...
-(defun create-keyvalue-table (con)
+(defun create-keyvalue-table (sc)
   ;; the "serial" specifiation here does not seem to work, (
   ;; apparently not supported by clsql, so I have to execute these
   ;; commands specifically.  This may be a database-dependent way of doing
@@ -334,25 +353,29 @@
   ;; CREATE-SEQUENCE and SEQUENCE-NEXT.  That would solve our problem!
 
   ;; ALL OF THIS needs to be inside a transaction.
-
+  (let* ((con (controller-db sc)))
 ;; At one time this was conditional, but all NEW repositories should have this.
-  (clsql::create-sequence [serial] :database con)
-  (clsql::query
-   (format nil "create table keyvalue (
+    (if (supports-sequence sc) 
+	(progn
+	  (clsql::create-sequence [serial] :database con)
+	  (clsql::query
+	   (format nil "create table keyvalue (
  pk integer PRIMARY KEY DEFAULT nextval('serial'),
  clctn_id integer NOT NULL,
  key varchar NOT NULL,
  value varchar
  )")
-   :database con)
-;;     (clsql::create-table [keyvalue]
-;;   		       ;; This is most likely to work with any database system..
-;;   		       '(
-;;   			 ([clctn_id] integer :not-null)
-;;   			 ([key] text :not-null)
-;;   			 ([value] text)
-;;   			 ) 
-;;   		       :database con)
+	 :database con)
+	)
+	(clsql::create-table [keyvalue]
+			   ;; This is most likely to work with any database system..
+			   '(
+			     ([clctn_id] integer :not-null)
+			     ([key] text :not-null)
+			     ([value] text)
+			     ) 
+			   :database con)
+      )
 
 ;;   	      :constraints '("PRIMARY KEY (clctn_id key)"
 ;;   				     "UNIQUE (clctn_id,key)")
@@ -380,7 +403,7 @@
 		      :attributes '([clctn_id] [key])
 		      :database con)
   ;;)
-  )
+  ))
 
 (defmethod database-version ((sc sql-store-controller))
   "A version determination for a given store
@@ -397,13 +420,6 @@
 	  (read-from-string (caar tuples))
 	  nil))))
 
-(defun set-database-version (sc)
-  (let ((con (controller-db sc)))
-    (clsql::insert-records :into [version]
-			   :attributes '(dbversion)
-			   :values (list (format nil "~A" *elephant-code-version*))
-			   :database con)))
-
 
 (defmethod open-controller ((sc sql-store-controller)
 			    ;; At present these three have no meaning
@@ -427,13 +443,11 @@
       ;; it does not, we need to create it..
       (unless (keyvalue-table-exists con)
 	  (with-transaction (:store-controller sc)
-	    (create-keyvalue-table con)))
+	    (create-keyvalue-table sc)))
       (setf (uses-pk-of sc) (query-uses-pk con))
       (unless (version-table-exists con)
 	(with-transaction (:store-controller sc)
-	  (create-version-table con)))
-      ;; Set elephant version if new
-      (when new-p (set-database-version sc))
+	  (create-version-table sc)))
       (initialize-serializer sc)
       ;; These should get oid 0 and 1 respectively 
       (setf (slot-value sc 'root) (make-instance 'sql-btree :sc sc :from-oid 0))




More information about the Elephant-cvs mailing list