db.(sqlite.)errors: add sql-index-exists error

char-rename
Alexander Iljin 2016-02-20 22:00:50 +04:00 committed by John Benediktsson
parent ca19a01c1b
commit 9c9764cc2d
3 changed files with 18 additions and 0 deletions

View File

@ -43,6 +43,11 @@ TUPLE: sql-database-exists < sql-error message ;
: <sql-database-exists> ( message -- error )
f swap sql-database-exists boa ;
TUPLE: sql-index-exists < sql-error name ;
: <sql-index-exists> ( name -- error )
f swap sql-index-exists boa ;
: ignore-error ( quot word -- )
'[ dup @ [ drop ] [ rethrow ] if ] recover ; inline
@ -60,3 +65,6 @@ TUPLE: sql-database-exists < sql-error message ;
: ignore-database-exists ( quot -- )
[ sql-database-exists? ] ignore-error ; inline
: ignore-index-exists ( quot -- )
[ sql-index-exists? ] ignore-error ; inline

View File

@ -21,5 +21,13 @@ db.sqlite kernel locals tools.test ;
{ [ sql-table-exists? ] [ table>> "foo" = ] } 1&&
] must-fail-with
"create index main_index on foo(id);" sql-command
[
"create index main_index on foo(id);" sql-command
] [
{ [ sql-index-exists? ] [ name>> "main_index" = ] } 1&&
] must-fail-with
] with-db
] with-test-file

View File

@ -14,6 +14,8 @@ AlreadyExists = " already exists"
SqliteError =
"table " (!(AlreadyExists).)+:table AlreadyExists
=> [[ table >string <sql-table-exists> ]]
| "index " (!(AlreadyExists).)+:name AlreadyExists
=> [[ name >string <sql-index-exists> ]]
| "no such table: " .+:table
=> [[ table >string <sql-table-missing> ]]
| .*:error