Racket db disconnect引发异常

时间:2015-06-07 05:24:25

标签: sqlite racket

我正在使用带有racket的db模块的sqlite数据库。在由于重复的密钥违规处理失败的插入或更新后,如果我尝试使用

断开连接
(disconnect dbconn)

它成功断开连接,但是我收到以下错误

disconnect: abort due to contraint violation

我正在使用

包装断开连接功能
(define (my-disconnect dbconn)
     (with-handlers ([exn:fail? (lambda (e) (void))])
         (disconnect dbconn)))

但有没有办法阻止断开连接错误?

更新 这似乎是Racket 5.2中的一个错误,它在以后的版本中得到修复。不幸的是,我坚持使用Racket 5.2。这是一个有这个问题的小程序。

#lang racket

(require db)

(define db-file "db.sqlite")
(define dbconn (sqlite3-connect #:database db-file #:mode 'create))

(query-exec dbconn "CREATE TABLE IF NOT EXISTS cats (\"cat_pk\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, \"cat_name\" TEXT)")

(query-exec dbconn "CREATE TABLE IF NOT EXISTS kittens (\"kitten_pk\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, \"kitten_name\" TEXT, cat_fk INTEGER NOT NU    LL, UNIQUE (cat_fk, kitten_name), FOREIGN KEY(cat_fk) REFERENCES cats (cat_pk))")

(query-exec dbconn "INSERT INTO cats (cat_name) VALUES (\"Dorothy\")")

(query-exec dbconn "INSERT INTO kittens (kitten_name, cat_fk) VALUES (\"John\", 1)")

(with-handlers [(exn:fail? (lambda (e) "Opps"))]
     (query-exec dbconn "INSERT INTO kittens (kitten_name, cat_fk) VALUES (\"John\", 1)"))

(disconnect dbconn)

在Racket 5.2中我得到了

"Opps"
disconnect: abort due to contraint violation

 === context ===
/usr/share/racket/collects/db/private/sqlite3/connection.rkt:257:8
/usr/share/racket/collects/db/private/sqlite3/connection.rkt:168:14: for-loop
/usr/share/racket/collects/db/private/sqlite3/connection.rkt:161:6: go
/users/user/www/test/test.rkt: [running body]

在Racket 6.2中我只得到

"Opps"

0 个答案:

没有答案