I am trying to use the trivial SELECT in CLSQL. I tried many permutations, as shown below:
(clsql:select 'dept_name
:from 'dept
:where (= 'dept_id 1))
;; Error
;; DEPT_ID is not of type NUMBER
;; though dept_id is of type INTEGER
(clsql:select 'dept_name
:from 'dept
:where [= id 'dept_id])
;; Error
;; The variable [= is unbound.
;; [Condition of type UNBOUND-VARIABLE]
(clsql:select [dept.dept_name]
:from [dept]
:where [= [dept.dept_id] 2])
;; Error
;; The variable [DEPT.DEPT_NAME] is unbound.
(clsql:select 'dept
:where [= [slot-value 'dept 'dept-id] 1])
;; Error
;; The variable [= is unbound.
;; [Condition of type UNBOUND-VARIABLE]
However, the query
(clsql:select 'dept_name
:from 'dept)
returns all the department names in a list of one element (dept_name)
lists.
I have declared a view class.
(clsql:def-view-class dept ()
((dept-id
:db-kind :key
:db-constraints :not-null
:type integer
:initarg :dept-id)
(dept-name
:accessor dept-name
:type (string 10)
:initarg :dept-name))
(:base-table dept))
corresponding to the table dept
with two attributes.
I have also enabled
(clsql:locally-enable-sql-reader-syntax)
I don't know what I am missing and how to make it work.
I think all my experiments were wrong. First, instead of using
(clsql:locally-enable-sql-reader-syntax)
we need to use(clsql:enable-sql-reader-syntax)
. Locally is applicable only within a file. Please refer to this comment in Reddit Forum.