"No source tables supplied to select statement."

Petter Gustad <[email protected]> Fri, 19 Apr 2013 14:57:20 +0200 (CEST)
Newsgroups gmane.lisp.clsql.general
Message-ID <[email protected]>
I keep getting the above error if I define the following form inside a
function. I have the SQL reader macros enabled:

REGLIB> (get-macro-character #\[ )
#<FUNCTION CLSQL-SYS::SQL-READER-OPEN>
NIL

If I simply run it it in the REPL it works as expected:

REGLIB> (first (clsql:select [max [id]] :from [regrun] :flatp t :field-names nil :database *database*))
1338

But if I embed it inside a function it will not work:

REGLIB> (defun get-latest-regrun-id (&optional (db *database*))
  "return the id of the latest regrun"
  (first (clsql:select [max [id]] 
 		       :from [regrun]
		       :flatp t 
		       :field-names nil
		       :database db)))

STYLE-WARNING: redefining REGLIB::GET-LATEST-REGRUN-ID in DEFUN
GET-LATEST-REGRUN-ID
REGLIB> (get-latest-regrun *database*)
; Evaluation aborted on #<SIMPLE-ERROR "No source tables supplied to select statement." {1007195083}>.

The result is the same if I compile the function either in SLIME or by
using asdf:load-system.

The odd thing is that it used to work at some point and I have
struggled with the same problem in the past. I resolved it at the time
by adding the following to the source files which are using the
sql-reader-syntax:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (setq *readtable* (copy-readtable))
  (clsql:locally-disable-sql-reader-syntax)
  (clsql:locally-enable-sql-reader-syntax)

  (unless (get-macro-character #\[ )
    (error "(get-macro-character #\[ ) returned nil, it should be a #<FUNCTION CLSQL-SYS::SQL-READER-OPEN>")))

But now I'm using this all the time and it does not help. Buf if I
define an identical function with a different name in the REPL it
works:

REGLIB> (defun dummy (&optional (db *database*))
  "return the id of the latest regrun"
  (first (clsql:select [max [id]] 
		       :from [regrun]
		       :flatp t 
		       :field-names nil
		       :database db)))

DUMMY
REGLIB> (dummy)
1338

So it might be related to the way it's built. If I try to force it to
rebuild using:

REGLIB> (asdf:load-system :reglib :force t)

The result is still the same. Any ideas how to resolve this? 


Here's some metrics for my system:

REGLIB> (asdf:component-version (asdf:find-system :clsql))
"6.2"
REGLIB> (database-type *database*)
:POSTGRESQL-SOCKET
REGLIB> (asdf:component-version (asdf:find-system :asdf))
"2.26"
REGLIB> (lisp-implementation-type)
"SBCL"
REGLIB> (lisp-implementation-version)
"1.1.2"
REGLIB> (machine-type)
"X86-64"

TIA
//Petter