From: Gabor Melis
Subject: USQL headaches
Date: 
Message-ID: <fb0fb805.0307040636.2a2c36ad@posting.google.com>
I am puzzled by USQL's behaviour. The experiment below was done after
the tutorial was loaded. [1] shows that there is no automatic
synchronization between an object and its mapping (i.e. the record in
the database). [2] shows that not even UPDATE-INSTANCE-FROM-DB
refreshes the EMPLOYEES join slot of COMPANY.

(defun select-lenin ()
  (car (sql:select 'employee
                   :where [= [slot-value 'employee 'emplid] 1])))

;; [1]
(let ((lenin (select-lenin))
      (lenin2 (select-lenin)))
  (setf (employee-email lenin) ยทยทยทยท@qwe")
  (update-records-from-instance lenin)
  (princ (employee-email lenin))
  (princ (employee-email lenin2)) ; the old value is there
  (update-instance-from-db lenin2)
  (princ (employee-email lenin2))
  (princ (employee-email (select-lenin))))

;; [2]
(company-employees company1)
(delete-instance-records employee1)
(company-employees company1) ; employee1 still seems to be there
(update-instance-from-db company1)
(company-employees company1) ; and still, a select cures it of course:
(company-employees
 (car (sql:select 'company
                  :where [= [slot-value 'company 'companyid] 1])))

So, is there a way to:

- update a join slot short of doing a select?

- to refresh/invalidate all objects in memory that have
something to do with an update? For example when an employee is added
it would be nice to update the appropriate company instances in one
go.

- or to make USQL refresh slots on access?

- and to commit all changes made to objects (mapped to the database,
of course) within a given form?

Or are these problems the result of the wrong approach: having objects
around for extended periods of time instead of selecting them every
time they are needed?


Cheers, Gabor Melis