Kevin Rosenberg | 12 Sep 2007 21:19
Favicon

CLSQL Mail List Changes

Sorry for the cross-posting -- eliminating cross-posting that is
actually a goal of this message.

Since requests for help are often intermingled with development issues
(and to a lesser degree in the other direction), and to reduce the
need to subscribe to multiple lists, I've merged the CLSQL-devel
and CLSQL-help mail lists into a single, new mail list: CLSQL. I'll
still keep CLSQL-announce as a low-traffic list for announcements,
though, an announcement hasn't been made in years. I'd be happy to
merge that list as well, but I think it does make sense to have a
separate list for traffic-sensitive subscribers.

One potential issue with the merge is that if you have subscribed to
CLSQL-devel and CLSQL-help with two *different* email addresses, both
addresses will be included in the merge so you might get duplicate
messages. But, mailman does make it easy for you to unsubscribe one of
the email addresses.

A second issue is that archives will remain available on clsql-devel
and clsql-help web sites. I will look into merging those archives into
the new mail list's web site. But, I'm not sure that will be feasible.

Barring a good argument against (or at least a few desparate pleas), I
plan on implementing this change in the next week. However, if you
have concerns or objections to this change, please send me email
directly (off-list).

--

-- 
Kevin Rosenberg
kevin@...
(Continue reading)

Saurabh Nanda | 12 Sep 2007 07:55
Picon

[Patch] Update view-database only if the transaction succeeded

Hi Kevin,

I've modified the behaviour of update-records-from-instance and
with-transaction to not set the view-database slot in  all the new
objects inserted when inside a transaction until the transaction is
fully committed.

Earlier, even if a transaction failed, and the objects were not
actually inserted in the DB, the view-database slot was being set.
This was causing problems while trying to re-insert the records -
update-records-from-instance would try to update the records instead
of inserting.

(This is the first time I'm using git so please guide me about the
correct way of submitting patches.)

Saurabh.
--

-- 
http://nandz.blogspot.com
http://foodieforlife.blogspot.com
From ba8cff551c4520a2ee40156a04ce8d3728a250cb Mon Sep 17 00:00:00 2001
From: Saurabh Nanda <saurabhnanda <at> gmail.com>
Date: Wed, 12 Sep 2007 11:21:03 +0530
Subject: [PATCH] o Modified the behaviour of update-records-from-instance and with-transaction to not
set the view-database slot in
all the new objects inserted when inside a transaction unil the transaction is committed. Earlier, even if a
transaction fails, and the objects are not actually inserted in the DB, the view-database slot was being
set. This
(Continue reading)

Kevin Rosenberg | 10 Sep 2007 16:36
Favicon

Re: CLSQL source code repositories

Saurabh Nanda wrote:
> Hmm... hadn't thought of this approach. Wanted to get my stuff working at
> that point of time. So what would the implementation look like:
> 
> 1. Subclass standard-db-class to create extended-db-class (for example).
> 2. Create a  extended-db-object whose metaclass is extended-db-class
> 3. Create a def-extended-view-class macro which ensures that the metaclass
> of the class being defined is extended-db-class

I think it should look like what you what the object to
accomplish. From reading your statement below, it appears that you
want to have an object that contains a sequence/field name so that
a single primary key object can be automatically assigned and stored
with that object.

I think your suggestion below is probably best. But, assuming you want
to have only one sequence name for all objects of that class, the
proper way would be #1 above.

> To give some background about this entire sequences feature: I am very
> influenced from Ruby-on-Rails and their philosophy of convention over
> configuration. So, given that you follow a certain convention in your DB
> design there's a lot of stuff that ActiveRecord (the ORM software that Rails
> uses) can give you a lot of stuff that works like magic.

> If the object was read from a DB it is  updated, else it is inserted (this
> is the way update-records-from-instance works currently). In case the object
> is being inserted in the DB, I look up the sequence name from the metaclass,
> look up the first unbound key slot and assign it the next get the next
> sequence value.
(Continue reading)

Saurabh Nanda | 6 Sep 2007 09:30
Picon

CLSQL source code repositories

http://b9.com/archives/000089.html

Thanks a lot Kevin.

I'll be cloning the GIT repository for CLSQL shortly and putting in a lot of patches for new OODML features. See if you'll be interested in pulling them in the main repository.

Saurabh.
--
http://nandz.blogspot.com
http://foodieforlife.blogspot.com
_______________________________________________
CLSQL-Help mailing list
CLSQL-Help@...
http://lists.b9.com/mailman/listinfo/clsql-help
Saurabh Nanda | 16 Aug 2007 12:53
Picon

When is fault-join-slot called?

Hi,

Quick question: is fault-join-slot also triggered in a setf form? For
example, will the following form also trigger fault-join-slot?

(setf (slot-value parent-obj join-slot) join-object)

I'm seeing weird behaviour in some of my code, which is expecting me
to believe that this is the case.

Also, where exactly is the MOP configured to hook into this function?

Nandz.
--

-- 
http://nandz.blogspot.com
http://foodieforlife.blogspot.com
Matthew Lamari | 21 Jul 2007 01:51
Picon

Possible memory leak - LW/ODBC/Win32/Microsoft SQL Server 2K5

I am using CL 3.8.5 (uffi-1.5.18) on Lispworks 5/Win32 to connect to a
Microsoft SQL Server 2K5 database.

I connect with:
(connect (list nil nil nil :connection-string "Driver={SQL
Server};Server=MyServer;Database=MyDB;Uid=myuser;Pwd=MyPassword;")
:if-exists :new :database-type :odbc )

And run a query test with:
(loop for i from 1 to 1000000 do (query "select CAST('hello' as
varchar(4096))"))

This loop basically starts eating up ram from the process.  What is of
interest is that if I break out and GC, (room t) does not indicate any
rise in memory usage, implying that the ram is being eaten up in
foreign allocations?

Eventually, it runs to Lispwork's 1.5G limit and fails with:
Error: Failed to allocate foreign object of size 4002 [allocator STATIC]
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

Disconnect doesn't clean it up either.

Where should I go about tracking down this leak?

I realize that it is plausible that the leak may be at the driver
level or UFFI, not necessarily CLSQL.  However, I was wondering if
this is something that is a known issue for some aspect of the
platform I'm using, or if this is something that devs versed in CLSQL
could trivially track down, or at least point me in the right
direction.

Thanks,
Matt
Ricardo Boccato Alves | 17 Jul 2007 04:20
Picon

find-and-load-foreign-library and Oracle

Hi,

I am using Oracle on Linux and it gives a type error (on SBCL, CMUCL and CLISP) if I try:

(asdf:oos 'asdf:load-op :clsql-oracle)

It happens during the loading of oracle's library and I believe the problem is that the paths are expected to be strings (and some are pathnames).

I did a naive change in the function find-and-load-foreign-library and it now works fine.

If it is of any help, the change I did follows.

--- old-clsql/uffi/clsql-uffi-loader.lisp       2007-07-16 23:15: 04.000000000 -0300
+++ new-clsql/uffi/clsql-uffi-loader.lisp       2007-07-16 23:15:04.000000000 -0300
<at> <at> -33,7 +33,13 <at> <at>
      (loop for type in (uffi:foreign-library-types)
           thereis
           (loop for name in filenames
-                for pn = (make-pathname :name name :type type)
+                for pn = (if (pathnamep name)
+                             (make-pathname :host (pathname-host name)
+                                            :device (pathname-device name)
+                                            :directory (pathname-directory name)
+                                            :name (pathname-name name)
+                                            :type type)
+                             (make-pathname :name name :type type))
                 thereis (or
                           (try-load pn)
                          (loop for search-path in clsql:*foreign-library-search-paths*

Obs.: It works fine with SBCL on Windows.

[]s,
Ricardo Boccato Alves.

_______________________________________________
CLSQL-Devel mailing list
CLSQL-Devel@...
http://lists.b9.com/mailman/listinfo/clsql-devel
Nathan Bird | 16 Jun 2007 00:38
Favicon

ODBC BIGINT hacking

BIGINTs on ODBC didn't work for me. I hacked for a while and now it
does, but you probably won't like it. With this it actually reads
bigints as 8 byte signed integers instead of trying to read them in as a
string (which left me with the first half of the number).  I think this
has something to do with the way freetds or sqlserver structures that
column. It looks like bignum on odbc->postgres did work, it still works
in this patch.

The downside: I didn't figure out how to make it work with uffi. This
uses :long-long out of the cffi-uffi-compat library.  If someone can
figure out a comparable item in uffi, or can teach uffi then this might
be more useful, as is I'm posting it for reference as much as anything.

I also included a patch for switch from uffi to the cffi-uffi-compat
library if anyone with this problem (I have a feeling there aren't many
of us:-) is interested in trying that.

Nathan Bird

PS: and with that, all the local patches i have are submitted! Cheers,
and thanks for the great library.
Thu Jun 14 16:28:20 EDT 2007  Nathan Bird <nathan@...>
  * switiching to use cffi-uffi-compat instead of uffi
diff -rN -u old-clsql/clsql-mysql.asd new-clsql/clsql-mysql.asd
--- old-clsql/clsql-mysql.asd	2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-mysql.asd	2007-06-15 18:35:51.000000000 -0400
 <at>  <at>  -80,7 +80,7  <at>  <at> 
   :description "Common Lisp SQL MySQL Driver"
   :long-description "cl-sql-mysql package provides a database driver to the MySQL database system."

-  :depends-on (uffi clsql clsql-uffi)
+  :depends-on (cffi-uffi-compat clsql clsql-uffi)
   :components
   ((:module :db-mysql
 	    :components
diff -rN -u old-clsql/clsql-odbc.asd new-clsql/clsql-odbc.asd
--- old-clsql/clsql-odbc.asd	2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-odbc.asd	2007-06-15 18:35:51.000000000 -0400
 <at>  <at>  -27,7 +27,7  <at>  <at> 
   :description "Common Lisp SQL ODBC Driver"
   :long-description "cl-sql-odbc package provides a database driver to the ODBC database system."

-  :depends-on (uffi clsql clsql-uffi)
+  :depends-on (cffi-uffi-compat clsql clsql-uffi)
   :components
   ((:module :db-odbc
 	    :components
diff -rN -u old-clsql/clsql-postgresql-socket.asd new-clsql/clsql-postgresql-socket.asd
--- old-clsql/clsql-postgresql-socket.asd	2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-postgresql-socket.asd	2007-06-15 18:35:51.000000000 -0400
 <at>  <at>  -29,7 +29,7  <at>  <at> 
   :description "Common Lisp SQL PostgreSQL Socket Driver"
   :long-description "cl-sql-postgresql-socket package provides a database driver to the PostgreSQL
database via a socket interface."

-  :depends-on (clsql uffi md5 #+sbcl sb-bsd-sockets)
+  :depends-on (clsql cffi-uffi-compat md5 #+sbcl sb-bsd-sockets)
   :components
   ((:module :db-postgresql-socket
 	    :components
diff -rN -u old-clsql/clsql-postgresql.asd new-clsql/clsql-postgresql.asd
--- old-clsql/clsql-postgresql.asd	2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-postgresql.asd	2007-06-15 18:35:51.000000000 -0400
 <at>  <at>  -29,7 +29,7  <at>  <at> 
   :description "Common Lisp PostgreSQL API Driver"
   :long-description "cl-sql-postgresql package provides a the database driver for the PostgreSQL API."

-  :depends-on (uffi clsql clsql-uffi)
+  :depends-on (cffi-uffi-compat clsql clsql-uffi)
   :components
   ((:module :db-postgresql
 	    :components
diff -rN -u old-clsql/clsql-uffi.asd new-clsql/clsql-uffi.asd
--- old-clsql/clsql-uffi.asd	2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-uffi.asd	2007-06-15 18:35:51.000000000 -0400
 <at>  <at>  -79,7 +79,7  <at>  <at> 
   :description "Common UFFI Helper functions for Common Lisp SQL Interface Library"
   :long-description "cl-sql-uffi package provides common helper functions using the UFFI for the CLSQL package."

-  :depends-on (uffi clsql)
+  :depends-on (cffi-uffi-compat clsql)

   :components
   ((:module :uffi
diff -rN -u old-clsql/clsql.asd new-clsql/clsql.asd
--- old-clsql/clsql.asd	2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql.asd	2007-06-15 18:35:51.000000000 -0400
 <at>  <at>  -27,7 +27,7  <at>  <at> 
 ;; need to load uffi for below perform :after method
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (unless (find-package 'uffi)
-    (asdf:operate 'asdf:load-op 'uffi)))
+    (asdf:operate 'asdf:load-op 'cffi-uffi-compat)))

 (defsystem clsql
     :name "CLSQL"

Thu Jun 14 15:25:43 EDT 2007  Nathan Bird <nathan@...>
  * Implementing bigint support for odbc + mssql
diff -rN -u old-clsql/db-odbc/odbc-api.lisp new-clsql/db-odbc/odbc-api.lisp
--- old-clsql/db-odbc/odbc-api.lisp	2007-06-15 17:57:28.000000000 -0400
+++ new-clsql/db-odbc/odbc-api.lisp	2007-06-15 17:57:28.000000000 -0400
 <at>  <at>  -240,7 +240,7  <at>  <at> 
     (SQLTransact
      henv hdbc $SQL_ROLLBACK)))

-; col-nr is zero-based in Lisp
+; col-nr is zero-based in Lisp but 1 based in sql
 ; col-nr = :bookmark retrieves a bookmark.
 (defun %bind-column (hstmt column-nr c-type data-ptr precision out-len-ptr)
   (with-error-handling
 <at>  <at>  -494,6 +494,7  <at>  <at> 
 	   (deref-pointer column-nullable-p-ptr :short)))))))

 ;; parameter counting is 1-based
+;; this function isn't used, which is good because FreeTDS dosn't support it.
 (defun %describe-parameter (hstmt parameter-nr)
   (with-foreign-objects ((column-sql-type-ptr :short)
 			 (column-precision-ptr #.$ODBC-ULONG-TYPE)
 <at>  <at>  -584,9 +585,10  <at>  <at> 
 (defun sql-to-c-type (sql-type)
   (ecase sql-type
     ((#.$SQL_CHAR #.$SQL_VARCHAR #.$SQL_LONGVARCHAR
-      #.$SQL_NUMERIC #.$SQL_DECIMAL #.$SQL_BIGINT -8 -9 -10) $SQL_C_CHAR) ;; Added -10 for MSSQL ntext type
+      #.$SQL_NUMERIC #.$SQL_DECIMAL -8 -9 -10) $SQL_C_CHAR) ;; Added -10 for MSSQL ntext type
     (#.$SQL_INTEGER $SQL_C_SLONG)
     (#.$SQL_SMALLINT $SQL_C_SSHORT)
+    (#.$SQL_BIGINT $SQL_C_SBIGINT)
     (#.$SQL_DOUBLE $SQL_C_DOUBLE)
     (#.$SQL_FLOAT $SQL_C_DOUBLE)
     (#.$SQL_REAL $SQL_C_FLOAT)
 <at>  <at>  -604,6 +606,7  <at>  <at> 
 (def-type short-pointer-type (* :short))
 (def-type int-pointer-type (* :int))
 (def-type long-pointer-type (* #.$ODBC-LONG-TYPE))
+(def-type big-pointer-type (* #.$ODBC-BIG-TYPE))
 (def-type float-pointer-type (* :float))
 (def-type double-pointer-type (* :double))
 (def-type string-pointer-type (* :unsigned-char))
 <at>  <at>  -624,6 +627,10  <at>  <at> 
   (locally (declare (type long-pointer-type ptr))
     (deref-pointer ptr #.$ODBC-LONG-TYPE)))

+(defun get-cast-big (ptr)
+  (locally (declare (type big-pointer-type ptr))
+    (deref-pointer ptr #.$ODBC-BIG-TYPE)))
+
 (defun get-cast-single-float (ptr)
   (locally (declare (type float-pointer-type ptr))
     (deref-pointer ptr :float)))
 <at>  <at>  -670,8 +677,7  <at>  <at> 
 		   (#.$SQL_C_SSHORT (get-cast-short data-ptr)) ;; ?
 		   (#.$SQL_SMALLINT (get-cast-short data-ptr)) ;; ??
 		   (#.$SQL_INTEGER (get-cast-int data-ptr))
-		   (#.$SQL_BIGINT (read-from-string
-				   (get-cast-foreign-string data-ptr)))
+		   (#.$SQL_BIGINT (get-cast-big data-ptr))
 		   (#.$SQL_DECIMAL
 		    (let ((*read-base* 10))
 		      (read-from-string (get-cast-foreign-string data-ptr))))
 <at>  <at>  -741,6 +747,7  <at>  <at> 
             (#.$SQL_C_BIT (uffi:allocate-foreign-object :byte))
             (#.$SQL_C_STINYINT (uffi:allocate-foreign-object :byte))
             (#.$SQL_C_SSHORT (uffi:allocate-foreign-object :short))
+	    (#.$SQL_C_SBIGINT (uffi:allocate-foreign-object #.$ODBC-BIG-TYPE))
             (#.$SQL_C_CHAR (uffi:allocate-foreign-string (1+ size)))
             (#.$SQL_C_BINARY (uffi:allocate-foreign-string (1+ (* 2 size))))
             (t
diff -rN -u old-clsql/db-odbc/odbc-constants.lisp new-clsql/db-odbc/odbc-constants.lisp
--- old-clsql/db-odbc/odbc-constants.lisp	2007-06-15 17:57:28.000000000 -0400
+++ new-clsql/db-odbc/odbc-constants.lisp	2007-06-15 17:57:28.000000000 -0400
 <at>  <at>  -21,6 +21,7  <at>  <at> 
 ;; on SuSE AMD64 9.0, unixODBC is compiled with with SQLLEN being 4 bytes long
 (defconstant $ODBC-LONG-TYPE :int)
 (defconstant $ODBC-ULONG-TYPE :unsigned-int)
+(defconstant $ODBC-BIG-TYPE :long-long)

 ;; (defconstant $ODBCVER	#x0210)

 <at>  <at>  -934,6 +935,7  <at>  <at> 
 (defconstant $SQL_C_BINARY $SQL_BINARY)
 (defconstant $SQL_C_BIT $SQL_BIT)
 (defconstant $SQL_C_TINYINT $SQL_TINYINT)
+(defconstant $SQL_C_SBIGINT (+ $SQL_BIGINT $SQL_SIGNED_OFFSET))
 (defconstant $SQL_C_SLONG (+ $SQL_C_LONG $SQL_SIGNED_OFFSET)) ;; SIGNED INTEGER
 (defconstant $SQL_C_SSHORT (+ $SQL_C_SHORT $SQL_SIGNED_OFFSET)) ;; SIGNED SMALLINT
 (defconstant $SQL_C_STINYINT (+ $SQL_TINYINT $SQL_SIGNED_OFFSET)) ;; SIGNED TINYINT
diff -rN -u old-clsql/db-odbc/odbc-dbi.lisp new-clsql/db-odbc/odbc-dbi.lisp
--- old-clsql/db-odbc/odbc-dbi.lisp	2007-06-15 17:57:28.000000000 -0400
+++ new-clsql/db-odbc/odbc-dbi.lisp	2007-06-15 17:57:28.000000000 -0400
 <at>  <at>  -454,22 +454,19  <at>  <at> 
     (setf computed-result-types (make-array column-count))
     (dotimes (i column-count)
       (setf (aref computed-result-types i) 
-	(cond
-	 ((consp result-types)
-	  (nth i result-types))
-	 ((eq result-types :auto)
-	  (if (eq (aref column-sql-types i) odbc::$SQL_BIGINT)
-	      :number
-	    (case (aref column-c-types i)
-	      (#.odbc::$SQL_C_SLONG :int)
-	      (#.odbc::$SQL_C_DOUBLE :double)
-	      (#.odbc::$SQL_C_FLOAT :float)
-	      (#.odbc::$SQL_C_SSHORT :short)
-	      (#.odbc::$SQL_C_STINYINT :short)
-	      (#.odbc::$SQL_BIGINT :short)
-	      (t t))))
-	  (t
-	   t)))))
+	    (cond
+	      ((consp result-types)
+	       (nth i result-types))
+	      ((eq result-types :auto)
+	       (case (aref column-c-types i)
+		 (#.odbc::$SQL_C_SLONG :int)
+		 (#.odbc::$SQL_C_DOUBLE :double)
+		 (#.odbc::$SQL_C_FLOAT :float)
+		 (#.odbc::$SQL_C_SSHORT :short)
+		 (#.odbc::$SQL_C_STINYINT :short)
+		 (#.odbc::$SQL_C_SBIGINT #.odbc::$ODBC-BIG-TYPE)
+		 (t t)))
+	      (t t)))))
   query)

 (defun db-close-query (query &key drop-p)
 <at>  <at>  -564,7 +561,8  <at>  <at> 
 (defun sql-to-lisp-type (sql-type)
   (ecase sql-type
     ((#.odbc::$SQL_CHAR #.odbc::$SQL_VARCHAR #.odbc::$SQL_LONGVARCHAR) :string)
-    ((#.odbc::$SQL_NUMERIC #.odbc::$SQL_DECIMAL #.odbc::$SQL_BIGINT) :string) ; ??
+    ((#.odbc::$SQL_NUMERIC #.odbc::$SQL_DECIMAL ) :string) ; ??
+    (#.odbc::$SQL_BIGINT #.odbc::$ODBC-BIG-TYPE)
     (#.odbc::$SQL_INTEGER #.odbc::$ODBC-LONG-TYPE)
     (#.odbc::$SQL_SMALLINT :short)
     ((#.odbc::$SQL_FLOAT #.odbc::$SQL_DOUBLE) #.odbc::$ODBC-LONG-TYPE)

_______________________________________________
CLSQL-Devel mailing list
CLSQL-Devel@...
http://lists.b9.com/mailman/listinfo/clsql-devel
Nathan Bird | 15 Jun 2007 23:54
Favicon

ODBC -> MSSQL transactions (HACK)

I had some problems with transactions, here is a hack around that works
for me. It is based on the fact that apparently mssql requires the
"transaction" keyword in "commit transaction" when it is over odbc. 
ODBC actually has a different scheme for transactions based on turning
off autocommit, and then doing the commit manually with SQLEndTran or
somesuch, that looked more difficult and with this all the tests pass. :-)

clsql -> unixodbc -> freetds (0.63) -> mssql 2000

Nathan Bird
Nathan Bird | 15 Jun 2007 22:20
Favicon

SBCL calculating key-slots and finalize-inheritance

I hit a weird bug the other day where compiling a file of a bunch of
def-view-class(es). The problem is that the key-slots slot on the
standard-db-class for some of the view-classes aren't being filled
properly.

Most of it works fine but there are several classes that have identical
column lists/slot definitions. These tables in the database were all
created via another macro elsewhere to hold similar but logically
distinct data. After compilation, the first one in the file has the
correct key-slots, but the rest are empty. Recompiling the file fills
the key-slots for all of them correctly, but putting the file in my .asd
twice didn't appear to be a good solution.

The solution I found (patch attached) is to do the same for SBCL as is
being done for allegro in this case: calculate the key-slots in
FINALIZE-INHERITANCE :AFTER. This makes some amount of sense, but I
don't know why it doesn't work from the INITIALIZE-INSTANCE :AROUND  so
this may still be missing something.

With this patch it works for me in sbcl 1.0.5 and 1.0.6.

Nathan Bird
Thu Jun  7 17:00:09 EDT 2007  Nathan Bird <nathan@...>
  * Set the key-slots :after FINALIZE-INHERITANCE for sbcl
diff -rN -u old-clsql/sql/metaclasses.lisp new-clsql/sql/metaclasses.lisp
--- old-clsql/sql/metaclasses.lisp	2007-06-15 11:59:00.000000000 -0400
+++ new-clsql/sql/metaclasses.lisp	2007-06-15 11:59:00.000000000 -0400
 <at>  <at>  -192,13 +192,13  <at>  <at> 
       (setq all-slots (remove-if #'not-db-col all-slots))
       (setq all-slots (stable-sort all-slots #'string< :key #'car))
       (setf (object-definition class) all-slots))
-    #-allegro
+    #-(or sbcl allegro)
     (setf (key-slots class) (remove-if-not (lambda (slot)
 					     (eql (slot-value slot 'db-kind)
 						  :key))
 					   (ordered-class-slots class)))))

-#+allegro
+#+(or sbcl allegro)
 (defmethod finalize-inheritance :after ((class standard-db-class))
   (setf (key-slots class) (remove-if-not (lambda (slot)
 					   (eql (slot-value slot 'db-kind)

_______________________________________________
CLSQL-Devel mailing list
CLSQL-Devel@...
http://lists.b9.com/mailman/listinfo/clsql-devel
Saurabh Nanda | 28 May 2007 14:05
Picon

Bug in 'update-records-from-instance'

Hi,

I've been hacking around the CLSQL OODML/OODDL stuff for some time now, and just noticed that 'update-records-from-instance' assumes that the database connection of an object will be open at the time of updating the DB. Is this correct?

Here's some proof of concept code that hits this bug:

;;;
(defparameter *db-credentials* (list (list "//172.16.31.29/db" "user" "pass") :pool nil :database-type :oracle :if-exists :new :make-default nil))

;;;
(defmacro with-custom-database ((&key db-var (connection-args '*db-credentials*)) &body body)
  (let ((result (gensym "result-")))
    (unless db-var (setf db-var 'clsql:*default-database*))
    `(let ((,db-var (apply #'clsql:connect ,connection-args))
       (,result nil))
      (unwind-protect
       (let ((,db-var ,db-var))
         (setf ,result (progn , <at> body)))
    (clsql:disconnect :database ,db-var))
      ,result)))

;;;
(defun get-object (id)
  (with-custom-database ()
    (first (select 'student :where [= [id] id] :flatp t))))

;;
(defun poc ()
  (with-custom-database ()
    (let ((a (get-object 3)))
      (setf (student-name a) "Joe Stud")
      (update-records-from-instance a))))

The form '(update-records-from-instance a)' in the 'poc' functions throws a "Database is closed error" because of the way 'update-records-from-instance' uses the 'view-database' slot.

Regards,
Saurabh.
--
http://nandz.blogspot.com
http://foodieforlife.blogspot.com

_______________________________________________
CLSQL-Help mailing list
CLSQL-Help@...
http://lists.b9.com/mailman/listinfo/clsql-help

Gmane