db.sqlite: make sure select-tuple throws sql-table-missing etc.

freebsd-work
John Benediktsson 2019-01-03 12:39:37 -08:00
parent d66ea1e09c
commit f8de0c1caa
3 changed files with 22 additions and 13 deletions

View File

@ -1,20 +1,20 @@
! Copyright (C) 2008 Chris Double, Doug Coleman. ! Copyright (C) 2008 Chris Double, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data arrays calendar.format USING: accessors alien.c-types alien.data arrays calendar.format
calendar.parser combinators db db.errors db.sqlite.ffi db.types calendar.parser combinators db db.errors db.sqlite.errors
io.backend io.encodings.string io.encodings.utf8 kernel math db.sqlite.ffi db.types io.backend io.encodings.string
namespaces present sequences serialize urls ; io.encodings.utf8 kernel math namespaces present sequences
serialize urls ;
IN: db.sqlite.lib IN: db.sqlite.lib
ERROR: sqlite-error < db-error n string ; ERROR: sqlite-error < db-error n string ;
ERROR: sqlite-sql-error < sql-error n string ;
: sqlite-other-error ( n -- * ) : sqlite-other-error ( n -- * )
dup sqlite-error-messages nth sqlite-error ; dup sqlite-error-messages nth sqlite-error ;
: sqlite-statement-error ( -- * ) : sqlite-statement-error ( -- * )
SQLITE_ERROR db-connection get handle>> sqlite3_errmsg
db-connection get handle>> sqlite3_errmsg sqlite-sql-error ; parse-sqlite-sql-error throw ;
: sqlite-check-result ( n -- ) : sqlite-check-result ( n -- )
{ {

View File

@ -1,6 +1,7 @@
USING: accessors arrays db db.sqlite db.tuples db.types io.directories USING: accessors arrays db db.errors db.sqlite db.tuples
io.files.temp kernel layouts literals math.parser namespaces sequences db.types io.directories io.files.temp kernel layouts literals
sorting splitting tools.test ; math.parser namespaces sequences sorting splitting tools.test ;
IN: db.sqlite.tests IN: db.sqlite.tests
: normalize ( str -- str' ) : normalize ( str -- str' )
@ -247,3 +248,9 @@ watch "WATCH" {
num-test3 new select-tuple num-test3 new select-tuple
] with-db num>> ] with-db num>>
] unit-test ] unit-test
[
TUPLE: no-table name ;
no-table "NO_TABLE" { { "name" "NAME" VARCHAR } } define-persistent
test.db [ no-table new select-tuple ] with-db
] [ sql-table-missing? ] must-fail-with

View File

@ -331,7 +331,9 @@ M: sqlite-db-connection compound ( string seq -- new-string )
} case ; } case ;
M: sqlite-db-connection parse-db-error M: sqlite-db-connection parse-db-error
dup sqlite-error? [
dup n>> { dup n>> {
{ 1 [ string>> parse-sqlite-sql-error ] } { 1 [ string>> parse-sqlite-sql-error ] }
[ drop ] [ drop ]
} case ; } case
] when ;