]> gitweb.factorcode.org Git - factor.git/commitdiff
db.(sqlite.)errors: add sql-index-exists error
authorAlexander Iljin <ajsoft@yandex.ru>
Sat, 20 Feb 2016 18:00:50 +0000 (22:00 +0400)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 29 Jun 2016 21:17:57 +0000 (14:17 -0700)
basis/db/errors/errors.factor
basis/db/sqlite/errors/errors-tests.factor
basis/db/sqlite/errors/errors.factor

index f33b4c5b24001d3f8e2ba5ae77f347ff2c45714e..dab0a69330f0a48e560cee7d57962e6d0ecb8375 100644 (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
index 039c428350821b0984b8e08133403eee832d89bc..ab30633e39aaed8f56c9c84fd3ccb4c92cb4f71a 100644 (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
index ca55c3a8ca4e04a3711a9a4fda6ea17c34500ffb..9831018b55255e857335a35a75c24ca76bee344c 100644 (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