]> gitweb.factorcode.org Git - factor.git/commitdiff
add more postgres error handling, remove usage of ignore-errors in db.tuples
authorsheeple <sheeple@oberon.local>
Sun, 22 Feb 2009 03:59:23 +0000 (21:59 -0600)
committersheeple <sheeple@oberon.local>
Sun, 22 Feb 2009 03:59:23 +0000 (21:59 -0600)
basis/db/errors/errors.factor
basis/db/errors/postgresql/postgresql-tests.factor
basis/db/errors/postgresql/postgresql.factor
basis/db/tuples/tuples.factor

index 00aa56815465c8f3b3769b090cf8f60dbcc17d5e..5239086f939a2a298784413788c508f5a0f3db29 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel ;
+USING: accessors kernel continuations fry words ;
 IN: db.errors
 
 ERROR: db-error ;
@@ -8,6 +8,11 @@ ERROR: sql-error location ;
 
 ERROR: bad-schema ;
 
+ERROR: sql-unknown-error < sql-error message ;
+: <sql-unknown-error> ( message -- error )
+    \ sql-unknown-error new
+        swap >>message ;
+
 ERROR: sql-table-exists < sql-error table ;
 : <sql-table-exists> ( table -- error )
     \ sql-table-exists new
@@ -22,3 +27,28 @@ ERROR: sql-syntax-error < sql-error message ;
 : <sql-syntax-error> ( message -- error )
     \ sql-syntax-error new
         swap >>message ;
+
+ERROR: sql-function-exists < sql-error message ;
+: <sql-function-exists> ( message -- error )
+    \ sql-function-exists new
+        swap >>message ;
+
+ERROR: sql-function-missing < sql-error message ;
+: <sql-function-missing> ( message -- error )
+    \ sql-function-missing new
+        swap >>message ;
+
+: ignore-error ( quot word -- )
+    '[ dup _ execute [ drop ] [ rethrow ] if ] recover ; inline
+
+: ignore-table-exists ( quot -- )
+    \ sql-table-exists? ignore-error ; inline
+
+: ignore-table-missing ( quot -- )
+    \ sql-table-missing? ignore-error ; inline
+
+: ignore-function-exists ( quot -- )
+    \ sql-function-exists? ignore-error ; inline
+
+: ignore-function-missing ( quot -- )
+    \ sql-function-missing? ignore-error ; inline
index 770b325086e0c4a3877bf5a3066919a1222c7c96..9dbebe07126ca7c0e119b29f64b7d3b0dc889a2e 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors combinators.short-circuit db db.errors
 db.errors.postgresql db.postgresql io.files.unique kernel namespaces
-tools.test db.tester ;
+tools.test db.tester continuations ;
 IN: db.errors.postgresql.tests
 
 postgresql-test-db [
index fac10d092fcec8b61390711a3f6de82df803b1e2..2b79859050ff8cc9bf52a5afbe52cdc1614fee6e 100644 (file)
@@ -4,8 +4,6 @@ USING: kernel db.errors peg.ebnf strings sequences math
 combinators.short-circuit accessors math.parser ;
 IN: db.errors.postgresql
 
-! ERROR:  relation "foo" does not exist
-
 : quote? ( ch -- ? ) "'\"" member? ;
 
 : quoted? ( str -- ? )
@@ -24,18 +22,26 @@ EBNF: parse-postgresql-sql-error
 Error = "ERROR:" [ ]+
 
 TableError =
-    Error "relation " (!(" already exists").)+:table " already exists"
+    Error ("relation "|"table ")(!(" already exists").)+:table " already exists"
         => [[ table >string unquote <sql-table-exists> ]]
-    | Error "relation " (!(" does not exist").)+:table " does not exist"
+    | Error ("relation "|"table ")(!(" does not exist").)+:table " does not exist"
         => [[ table >string unquote <sql-table-missing> ]]
 
+FunctionError =
+    Error "function" (!(" already exists").)+:table " already exists"
+        => [[ table >string <sql-function-exists> ]]
+    | Error "function" (!(" does not exist").)+:table " does not exist"
+        => [[ table >string <sql-function-missing> ]]
+
 SyntaxError =
     Error "syntax error at end of input":error
         => [[ error >string <sql-syntax-error> ]]
     | Error "syntax error at or near " .+:syntaxerror
         => [[ syntaxerror >string unquote <sql-syntax-error> ]]
 
-PostgresqlSqlError = (TableError | SyntaxError) 
+UnknownError = .* => [[ >string <sql-unknown-error> ]]
+
+PostgresqlSqlError = (TableError | FunctionError | SyntaxError | UnknownError) 
 
 ;EBNF
 
index 9edd5bac6995846b1fde1aa8087da5763eb08977..19d4be5fc8aa8c238ee97398104aa4093c46748c 100644 (file)
@@ -4,7 +4,7 @@ USING: arrays assocs classes db kernel namespaces
 classes.tuple words sequences slots math accessors
 math.parser io prettyprint db.types continuations
 destructors mirrors sets db.types db.private fry
-combinators.short-circuit ;
+combinators.short-circuit db.errors ;
 IN: db.tuples
 
 HOOK: create-sql-statement db-connection ( class -- object )
@@ -118,13 +118,15 @@ ERROR: no-defined-persistent object ;
     ensure-defined-persistent
     [
         '[
-            _ drop-sql-statement [ execute-statement ] with-disposals
-        ] ignore-errors
+            [
+                _ drop-sql-statement [ execute-statement ] with-disposals
+            ] ignore-table-missing
+        ] ignore-function-missing
     ] [ create-table ] bi ;
 
 : ensure-table ( class -- )
     ensure-defined-persistent
-    '[ _ create-table ] ignore-errors ;
+    '[ [ _ create-table ] ignore-table-exists ] ignore-function-exists ;
 
 : ensure-tables ( classes -- ) [ ensure-table ] each ;