add more postgres error handling, remove usage of ignore-errors in db.tuples
parent
d6d89e0a40
commit
02cec3a9f4
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors kernel ;
|
USING: accessors kernel continuations fry words ;
|
||||||
IN: db.errors
|
IN: db.errors
|
||||||
|
|
||||||
ERROR: db-error ;
|
ERROR: db-error ;
|
||||||
|
@ -8,6 +8,11 @@ ERROR: sql-error location ;
|
||||||
|
|
||||||
ERROR: bad-schema ;
|
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 ;
|
ERROR: sql-table-exists < sql-error table ;
|
||||||
: <sql-table-exists> ( table -- error )
|
: <sql-table-exists> ( table -- error )
|
||||||
\ sql-table-exists new
|
\ sql-table-exists new
|
||||||
|
@ -22,3 +27,28 @@ ERROR: sql-syntax-error < sql-error message ;
|
||||||
: <sql-syntax-error> ( message -- error )
|
: <sql-syntax-error> ( message -- error )
|
||||||
\ sql-syntax-error new
|
\ sql-syntax-error new
|
||||||
swap >>message ;
|
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
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors combinators.short-circuit db db.errors
|
USING: accessors combinators.short-circuit db db.errors
|
||||||
db.errors.postgresql db.postgresql io.files.unique kernel namespaces
|
db.errors.postgresql db.postgresql io.files.unique kernel namespaces
|
||||||
tools.test db.tester ;
|
tools.test db.tester continuations ;
|
||||||
IN: db.errors.postgresql.tests
|
IN: db.errors.postgresql.tests
|
||||||
|
|
||||||
postgresql-test-db [
|
postgresql-test-db [
|
||||||
|
|
|
@ -4,8 +4,6 @@ USING: kernel db.errors peg.ebnf strings sequences math
|
||||||
combinators.short-circuit accessors math.parser ;
|
combinators.short-circuit accessors math.parser ;
|
||||||
IN: db.errors.postgresql
|
IN: db.errors.postgresql
|
||||||
|
|
||||||
! ERROR: relation "foo" does not exist
|
|
||||||
|
|
||||||
: quote? ( ch -- ? ) "'\"" member? ;
|
: quote? ( ch -- ? ) "'\"" member? ;
|
||||||
|
|
||||||
: quoted? ( str -- ? )
|
: quoted? ( str -- ? )
|
||||||
|
@ -24,18 +22,26 @@ EBNF: parse-postgresql-sql-error
|
||||||
Error = "ERROR:" [ ]+
|
Error = "ERROR:" [ ]+
|
||||||
|
|
||||||
TableError =
|
TableError =
|
||||||
Error "relation " (!(" already exists").)+:table " already exists"
|
Error ("relation "|"table ")(!(" already exists").)+:table " already exists"
|
||||||
=> [[ table >string unquote <sql-table-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> ]]
|
=> [[ 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 =
|
SyntaxError =
|
||||||
Error "syntax error at end of input":error
|
Error "syntax error at end of input":error
|
||||||
=> [[ error >string <sql-syntax-error> ]]
|
=> [[ error >string <sql-syntax-error> ]]
|
||||||
| Error "syntax error at or near " .+:syntaxerror
|
| Error "syntax error at or near " .+:syntaxerror
|
||||||
=> [[ syntaxerror >string unquote <sql-syntax-error> ]]
|
=> [[ syntaxerror >string unquote <sql-syntax-error> ]]
|
||||||
|
|
||||||
PostgresqlSqlError = (TableError | SyntaxError)
|
UnknownError = .* => [[ >string <sql-unknown-error> ]]
|
||||||
|
|
||||||
|
PostgresqlSqlError = (TableError | FunctionError | SyntaxError | UnknownError)
|
||||||
|
|
||||||
;EBNF
|
;EBNF
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: arrays assocs classes db kernel namespaces
|
||||||
classes.tuple words sequences slots math accessors
|
classes.tuple words sequences slots math accessors
|
||||||
math.parser io prettyprint db.types continuations
|
math.parser io prettyprint db.types continuations
|
||||||
destructors mirrors sets db.types db.private fry
|
destructors mirrors sets db.types db.private fry
|
||||||
combinators.short-circuit ;
|
combinators.short-circuit db.errors ;
|
||||||
IN: db.tuples
|
IN: db.tuples
|
||||||
|
|
||||||
HOOK: create-sql-statement db-connection ( class -- object )
|
HOOK: create-sql-statement db-connection ( class -- object )
|
||||||
|
@ -118,13 +118,15 @@ ERROR: no-defined-persistent object ;
|
||||||
ensure-defined-persistent
|
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 ;
|
] [ create-table ] bi ;
|
||||||
|
|
||||||
: ensure-table ( class -- )
|
: ensure-table ( class -- )
|
||||||
ensure-defined-persistent
|
ensure-defined-persistent
|
||||||
'[ _ create-table ] ignore-errors ;
|
'[ [ _ create-table ] ignore-table-exists ] ignore-function-exists ;
|
||||||
|
|
||||||
: ensure-tables ( classes -- ) [ ensure-table ] each ;
|
: ensure-tables ( classes -- ) [ ensure-table ] each ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue