From 9c9764cc2d9cafeb79a76945cbe78d79218bb428 Mon Sep 17 00:00:00 2001 From: Alexander Iljin Date: Sat, 20 Feb 2016 22:00:50 +0400 Subject: [PATCH] db.(sqlite.)errors: add sql-index-exists error --- basis/db/errors/errors.factor | 8 ++++++++ basis/db/sqlite/errors/errors-tests.factor | 8 ++++++++ basis/db/sqlite/errors/errors.factor | 2 ++ 3 files changed, 18 insertions(+) diff --git a/basis/db/errors/errors.factor b/basis/db/errors/errors.factor index f33b4c5b24..dab0a69330 100644 --- a/basis/db/errors/errors.factor +++ b/basis/db/errors/errors.factor @@ -43,6 +43,11 @@ TUPLE: sql-database-exists < sql-error message ; : ( message -- error ) f swap sql-database-exists boa ; +TUPLE: sql-index-exists < sql-error name ; + +: ( 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 diff --git a/basis/db/sqlite/errors/errors-tests.factor b/basis/db/sqlite/errors/errors-tests.factor index 039c428350..ab30633e39 100644 --- a/basis/db/sqlite/errors/errors-tests.factor +++ b/basis/db/sqlite/errors/errors-tests.factor @@ -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 diff --git a/basis/db/sqlite/errors/errors.factor b/basis/db/sqlite/errors/errors.factor index ca55c3a8ca..9831018b55 100644 --- a/basis/db/sqlite/errors/errors.factor +++ b/basis/db/sqlite/errors/errors.factor @@ -14,6 +14,8 @@ AlreadyExists = " already exists" SqliteError = "table " (!(AlreadyExists).)+:table AlreadyExists => [[ table >string ]] + | "index " (!(AlreadyExists).)+:name AlreadyExists + => [[ name >string ]] | "no such table: " .+:table => [[ table >string ]] | .*:error