Lisp HUG Maillist Archive

Iteration syntax for UncommonSQL

Hi!

(I'm currently using UncommonSQL because I only have a license for LW
professional but I'm sending a copy to the LW mailing list because I
guess the answer is indepent of whether it's "Uncommon" or "Common".)

I'm using the OO interface to UncommonSQL and have created a view
class USER which maps to a database table USERS. Everything works fine
except for the fact that, in order to loop through all elements of the
database, I resort to things like

  (dolist (user (sql:select 'user))
    ..)

which conses up a list that I don't actually need (and which might be
large).

I'm aware of the iteration constructs described in
<http://www.lispworks.com/reference/sql-tutorial/index.html#section-4.3>
but I couldn't figure out how to use them with view classes.

Is there something that I'm missing?

Thanks,
Edi.

Re: Iteration syntax for UncommonSQL

Unable to parse email body. Email id is 787

Re: Iteration syntax for UncommonSQL

Nick Levine <ndl@ravenbrook.com> writes:

> Edi,
> 
> Take a look at the end of section 5.2 in the same document:
> 
>     Finally, we have at our disposal all the same iteration constructs
>     that we had before (section 4.3). This time the iteration focus is
>     not a record (i.e. a tuple of attributes) but a tuple of
>     instances. For example, returning to the iteration examples we
>     used before:
> 
>        CL-USER 361 > (do-query ((my-aardvark) [select 'species-list
>                                                       :where aardvark])
>                                (print my-aardvark))
> 
>        #<db-instance SPECIES-LIST 574209404>
> 
>        CL-USER 362 >
> 
> I have only tried this with Common SQL. Please let us know if you find
> that UncommonSQL is different.

That was how I hoped it would work. But it doesn't (CMUCL 18e-pre with
USQL checked out from CVS in December):

  * (sql:select 'user :where [= [fname] "Edi"])
  (#<USER {4816A08D}>)
  * (describe (car *))

  #<USER {4816A08D}> is an instance of class #<View-Metaclass USER {48030F8D}>:
   The following slots have :INSTANCE allocation:
   EDITING-CONTEXT        NIL
   VIEW-DATABASE          #<MAISQL-POSTGRESQL:POSTGRESQL-DATABASE {4854FC25}>
   FULL-NAME              "unbound"
   JACKPOT-DAYS           NIL
   BULI-POINTS-PER-DAY    #(0 0 0 0 0 ...)
   BULI-TOTO-PER-DAY      #(0 0 0 0 0 ...)
   BULI-POINTS            0
   MAX-MINUTES            60
   BULI-MAIL-DIFF         4
   WANT-BULI-MAIL         17
   FAVORITES              NIL
   PEUGEOT                NIL
   DISTRICT               "Hamburg"
   REGION                 "Nord"
   EMAIL                  "edi@agharta.de"
   LNAME                  "Weitz"
   FNAME                  "Edi"
   USER-ID                "dodod"
  * (sql:do-query ((my-user) [select 'user :where [= [fname] "Edi"]]) (print my-user))

  Error in function "DEFMETHOD MAKE-QUERY NIL":  No source tables supplied to select statement.

  Restarts:
    0: [ABORT] Return to Top-Level.

  Debug  (type H for help)

  ("DEFMETHOD MAKE-QUERY NIL" #<unused-arg> #<unused-arg> (USER :WHERE #<MAISQL-SYS::SQL-RELATIONAL-EXP (FNAME = 'Edi')>))
  Source: (ERROR "No source tables supplied to select statement.")
  0] :a
  * (sql:do-query ((my-user) (sql:select 'user :where [= [fname] "Edi"])) (print my-user))

  Type-error in KERNEL::OBJECT-NOT-TYPE-ERROR-HANDLER:  (#<USER {4819901D}>) is not of type (OR SIMPLE-BASE-STRING NULL (ALIEN:ALIEN (* (ALIEN:SIGNED 8))))

  Restarts:
    0: [ABORT] Return to Top-Level.

  Debug  (type H for help)

  (MAISQL-POSTGRESQL::%PG-QUERY-RESULT-SET #<MAISQL-POSTGRESQL:POSTGRESQL-DATABASE {4854FC25}> (#<USER {4819901D}>))
  Source: 
  ; File: /usr/local/lisp/source/uncommonsql/dbms/postgresql/glue-cmucl.lisp
  (PQEXEC CONN-PTR QUERY-EXPRESSION)
  0]  

Hmmm...

Re: Iteration syntax for UncommonSQL

Unable to parse email body. Email id is 789

Re: Iteration syntax for UncommonSQL

Unable to parse email body. Email id is 790

Re: Iteration syntax for UncommonSQL

Unable to parse email body. Email id is 791

Re: Iteration syntax for UncommonSQL

To provide an update to this: I recently updated my CVS version of
UncommonSQL and it _looks_ like they also support DO-QUERY for view
class objects now. I can't verify this because the current version
didn't build for me and at the moment I don't have the time to dig
around in the sources until it does.

However, it also seems that the implementation of DO-QUERY does
exactly what I originally wanted to avoid: It first stores the
complete result of the query and then uses an iteration construct (DO
in this case) to walk through it. I think/hope that the original
CommonSQL doesn't do this.

(Please note that these observations are just based on a superficial
glance at the code. Please correct me if I'm wrong.)

Edi.
Updated at: 2020-12-10 09:01 UTC