作为用 Racket 编写的 servlet 的一部分,我想创建一个函数,将请求绑定(以字符串作为键和值的 hasheq 表的形式)转换为 SQL 表行(再次编写为带字符串的 hasheq 表作为键和 sql 类型作为值)。当相关函数收到两个哈希表时,这一切似乎都按预期工作,此时它失败并出现以下错误:
请求绑定是:
'#hasheq(("lastname" . "Smith")
("firstname" . "John")
("birthdate" . "1900-10-25"))
列类型是
'#hasheq(("lastname" . "character varying")
("firstname" . "character varying")
("birthdate" . "date"))
错误信息是:
Servlet (@ /<... servlet URL ...>) exception:
hash-ref: no value found for key
key: "lastname"
奇怪的是,如果将这些哈希表与相关代码片段一起粘贴到 DrRacket 提示符,它运行时不会产生错误
The value "Smith" needs to be converted to type "character varying"
The value "John" needs to be converted to type "character varying"
The value "1900-10-25" needs to be converted to type "date"
我做错了什么?任何帮助是极大的赞赏!这是代码:
#lang racket
(define bindings-hash
'#hasheq(("lastname" . "Smith")
("firstname" . "John")
("birthdate" . "1900-10-25")))
(define types-hash
'#hasheq(("lastname" . "character varying")
("firstname" . "character varying")
("birthdate" . "date")))
(define (test)
(eprintf "The request bindings are \n~v\n" bindings-hash)
(eprintf "The column types are \n~v\n" types-hash)
(for ([(this-key this-value) (in-hash bindings-hash)])
(eprintf "The value ~v needs to be converted to type ~v\n"
this-value
(hash-ref types-hash this-key))))
(test)