common-lisp - CLSQL:本地启用 sql reader 语法
问题描述
我正在尝试在 CLSQL 中使用微不足道的 SELECT。我尝试了很多排列,如下图:
(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]
但是,查询
(clsql:select 'dept_name
:from 'dept)
返回一个元素(dept_name)
列表中的所有部门名称。
我已经声明了一个视图类。
(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))
对应表dept
有两个属性。
我也启用了
(clsql:locally-enable-sql-reader-syntax)
我不知道我错过了什么以及如何让它发挥作用。
解决方案
我认为我所有的实验都是错误的。首先,(clsql:locally-enable-sql-reader-syntax)
我们需要使用(clsql:enable-sql-reader-syntax)
. 本地仅适用于文件。请参阅 Reddit 论坛中的此评论。
推荐阅读
- xpath - Looking for all descendant elements which parent does not have this css class
- networking - Raspberry Pi 获得 192.168.xx 地址,但我家庭网络的其余部分是 10.21.179.x
- java - Java浮点自动舍入问题
- c# - 哪个集合可以更快地找到和删除具有最小值的元素
- android - 从 Kotlin 扩展 Java 类时构建期间未解决的引用
- oracle - 通过 CPAN Perl DBI:Oracle 返回的缺失/错误字符(缺失变音符号)
- android - 使用应用程序时重复通知
- amazon-web-services - AWS 上的 Azure Application Insights 与 Elastic Beanstalk?
- c# - 即使没有打开任何文档,Globals.ThisAddIn.Application.Documents.Count 也会返回 1
- java - 如何为节点迭代设置 do...while