Ken Causey | 2 Aug 21:58 2007

Symbolic SQL Syntax Tribulations

I'm having no end of headaches from trying to use the symbolic sql
syntax.

Example:

(do-cached-query ((coach-id user-id first-name last-name team-id)
		      [select ["coach_id"] ["user_id"] ["coach_first_name"]
["coach_last_name"] ["team_id"]
		      :from ["coaches"] :order-by ["coach_id"]])
      (unless (eq user-id 0)
	(let ((result (select ["email"] ["url"] ["pass"] ["newsletter"]
			      :from ["nuke_users"]
			      :where [= ["uid"] user-id])))
	  (when result
	    (format t "~A ~A ~A ~A ~A ~A~&" coach-id user-id first-name
last-name team-id result)))))

One minute that will compile fine another it won't or it won't execute. 

I end up with an error like

"odd number of elements in keyword/value list: ([ "coach_id" ] [
                                                 "user_id" ] [
                                                 "coach_first_name" ]
                                                 [ ...)"

I've tried executing (enable-sql-reader-syntax) in multiple packages, I
have it as

(eval-when (:compile-toplevel :load-toplevel :execute)
(Continue reading)

Ralf Mattes | 2 Aug 22:32 2007
Picon

Re: Symbolic SQL Syntax Tribulations

On Thu, 2007-08-02 at 14:58 -0500, Ken Causey wrote:
> I'm having no end of headaches from trying to use the symbolic sql
> syntax.
> 

Sorry, hit the wrong key ....

> I've tried executing (enable-sql-reader-syntax) in multiple packages, I
> have it as
> 
> (eval-when (:compile-toplevel :load-toplevel :execute)
> (enable-sql-reader-syntax))
> 

One thing to remember: SQL syntax extends the Lisp reader - so
load/compile/eval doesn't really matter (by the time the
compiler/interpreters "sees" the code all reader syntax is gone ...).
Yo need to tell the _reader_ to evaluate enable-sql-reader-syntax during
_reading_ of the code. The easiest was to do that:

 #.(enable-sql-reader-syntax)

> in the file where the syntax is used, etc.
> 
> Please enlighten me on the proper way to enable the syntax, it would
> also be nice if slime also recognized it when I ask it to macroexpand
> for example.

HTH Ralf Mattes

(Continue reading)

James Bielman | 2 Aug 22:50 2007

Re: Symbolic SQL Syntax Tribulations

On Thu, 2007-08-02 at 14:58 -0500, Ken Causey wrote:
> I'm having no end of headaches from trying to use the symbolic sql
> syntax.

[...]

> I've tried executing (enable-sql-reader-syntax) in multiple packages, I
> have it as
> 
> (eval-when (:compile-toplevel :load-toplevel :execute)
> (enable-sql-reader-syntax))
> 
> in the file where the syntax is used, etc.

At some point, the CLSQL syntax reader macros were (IMHO) broken,
in that you seem to need to disable the reader syntax at the end
of each compilation unit.

All of my files now look like:

  (in-package ...)
  (clsql:locally-enable-sql-reader-syntax)

  #| (defun hack () (select [...])) |#

  (clsql:locally-disable-sql-reader-syntax)
  ;; EOF

There's no need for an EVAL-WHEN, because the macro already expands
into one.
(Continue reading)

Ken Causey | 2 Aug 23:30 2007

Re: Symbolic SQL Syntax Tribulations

Well, I tried both Ralf and James solutions and in both cases I get

The variable [ is unbound.
   [Condition of type UNBOUND-VARIABLE]

and similar errors when executing (map-coaches) from :

(defun ensure-database (site-name)
  "Retrieve a new or existing database for the given site-name"
  (let ((connection-spec (get 'connection-specs site-name)))
    (assert (not (null connection-spec))
	    (connection-spec)
	    "Unable to find a connection specification for site ~S." site-name)
  (connect connection-spec
		  :if-exists :old
		  :database-type :mysql
		  :pool t)))

(defmacro with-database-for ((db-var site-name) &body body)
  "A macro to retrieve a database for a site-name and bind it locally"
  (let ((result (gensym)))
    `(let* ((,db-var (ensure-database ,site-name))
	    (,result (progn , <at> body)))
      (disconnect :database ,db-var)
      ,result)))

(defmacro do-cached-query (((&rest args) query-expression &key database
result-types) &body body)
  "Based on clsql's original do-query except that all of the results
are gathered and cached before the first invocation of body.  This
(Continue reading)

Jens Teich | 3 Aug 00:05 2007
Picon

Unicode Problems

Hi,

are there any plans to improve the unicode abilities of clsql?

I get slime session crashes when reading a bullet (hex 95) under linux
and sbcl 1.0.7 from a postgres db.

| Slime says: 
| Lisp connection closed unexpectedly: exited abnormally with code 256
|
| sbcl: 
| Event history end.
| Connection to Emacs lost. [
| condition: Unable to display error condition: #<SB-SYS:FD-STREAM> 
|            for "a socket" (BCAAB19) is closed.
| type:      SB-INT:STREAM-ENCODING-ERROR
| encoding:  :ISO-LATIN-1-UNIX style: :SPAWN dedicated: NIL]

I asked a similar thing in April before but I am not proceeded any further.

Might it be of any use to post this on sbcl mailing list or is this a 
clsql problem?

Jens
Harald Hanche-Olsen | 3 Aug 10:15 2007
Picon
Picon

Re: Unicode Problems

Please don't use reply-to when sending to mailing lists.  We want the
mailing list to get any replies as well!

+ "Jens Teich" <info <at> jensteich.de>:

| I get slime session crashes when reading a bullet (hex 95)

Wait a minute.  A bullet is not hex 95 in unicode.
Check this entry from UnicodeData.txt:

0095;<control>;Cc;0;BN;;;;;N;MESSAGE WAITING;;;;

| under linux and sbcl 1.0.7 from a postgres db.
| 
| | Slime says: 
| | Lisp connection closed unexpectedly: exited abnormally with code 256
| |
| | sbcl: 
| | Event history end.
| | Connection to Emacs lost. [
| | condition: Unable to display error condition: #<SB-SYS:FD-STREAM> 
| |            for "a socket" (BCAAB19) is closed.
| | type:      SB-INT:STREAM-ENCODING-ERROR
| | encoding:  :ISO-LATIN-1-UNIX style: :SPAWN dedicated: NIL]
|     
| 
| I asked a similar thing in April before but I am not proceeded any further.

| Might it be of any use to post this on sbcl mailing list or is this a 
| clsql problem?
(Continue reading)

Robert Synnott | 3 Aug 13:12 2007
Picon

Re: Unicode Problems

On 8/3/07, Harald Hanche-Olsen <hanche@...> wrote:
> Please don't use reply-to when sending to mailing lists.  We want the
> mailing list to get any replies as well!
>
> + "Jens Teich" <info@...>:
>
> | I get slime session crashes when reading a bullet (hex 95)
>
> Wait a minute.  A bullet is not hex 95 in unicode.
> Check this entry from UnicodeData.txt:
>
> 0095;<control>;Cc;0;BN;;;;;N;MESSAGE WAITING;;;;
>
> | under linux and sbcl 1.0.7 from a postgres db.
> |
> | | Slime says:
> | | Lisp connection closed unexpectedly: exited abnormally with code 256
> | |
> | | sbcl:
> | | Event history end.
> | | Connection to Emacs lost. [
> | | condition: Unable to display error condition: #<SB-SYS:FD-STREAM>
> | |            for "a socket" (BCAAB19) is closed.
> | | type:      SB-INT:STREAM-ENCODING-ERROR
> | | encoding:  :ISO-LATIN-1-UNIX style: :SPAWN dedicated: NIL]
> |
> |
> | I asked a similar thing in April before but I am not proceeded any further.
>
> | Might it be of any use to post this on sbcl mailing list or is this a
(Continue reading)

Jens Teich | 3 Aug 23:06 2007
Picon

Re: Unicode Problems


> cl-user> "Ā"
> "Ā"
> cl-user> (char * 0)
> #\LATIN_CAPITAL_LETTER_A_WITH_MACRON

When try this directly in sbcl without emacs and slime the result is

* (char * 0)

=> error: value 120 is not of type VECTOR

Jens

_______________________________________________
CLSQL-Help mailing list
CLSQL-Help <at> b9.com
http://lists.b9.com/mailman/listinfo/clsql-help
Jens Teich | 3 Aug 23:21 2007
Picon

Re: Unicode Problems

Jens Teich wrote:
>> cl-user> "Ā"
>> "Ā"
>> cl-user> (char * 0)
>> #\LATIN_CAPITAL_LETTER_A_WITH_MACRON
> 
> When try this directly in sbcl without emacs and slime the result is
> 
> * (char * 0)
> 
> => error: value 120 is not of type VECTOR

sorry nonsense.

didn't know how to type the first line and tried only the second one. stupid.

jens

_______________________________________________
CLSQL-Help mailing list
CLSQL-Help <at> b9.com
http://lists.b9.com/mailman/listinfo/clsql-help
Ralf Mattes | 3 Aug 23:56 2007
Picon

Re: Unicode Problems

On Fri, 2007-08-03 at 23:21 +0200, Jens Teich wrote:
> Jens Teich wrote:
> >> cl-user> "Ā"
> >> "Ā"
> >> cl-user> (char * 0)
> >> #\LATIN_CAPITAL_LETTER_A_WITH_MACRON
> > 
> > When try this directly in sbcl without emacs and slime the result is
> > 
> > * (char * 0)
> > 
> > => error: value 120 is not of type VECTOR
> 
> sorry nonsense.
> 
> didn't know how to type the first line and tried only the second one. stupid.

Looks like you might encounter encoding problems at three different
levels/places:

 postgres server <---[1]---> libpq <---[2]---> sbcl <---[3]---> emacs

 [1] To find out about the encoding used here connect to your database
and do a '(clsql:query "show client_encoding")'.

 [2] You need to see whether your sbcl supports unicode: what does
'(member :sb-unicode *features*)' give?

 [3] I usually set the swank/slime encoding expicitly in me emacs init
file:  (setq slime-net-coding-system 'utf-8-unix)
(Continue reading)


Gmane