1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel db.errors peg.ebnf strings sequences math
4 combinators.short-circuit accessors math.parser quoting
6 IN: db.postgresql.errors
8 EBNF: parse-postgresql-sql-error [=[
13 Error ("relation "|"table ")(!(" already exists").)+:table " already exists"
14 => [[ table >string unquote <sql-table-exists> ]]
15 | Error ("relation "|"table ")(!(" does not exist").)+:table " does not exist"
16 => [[ table >string unquote <sql-table-missing> ]]
19 Error ("database")(!(" already exists").)+:database " already exists"
20 => [[ database >string <sql-database-exists> ]]
23 Error "function" (!(" already exists").)+:table " already exists"
24 => [[ table >string <sql-function-exists> ]]
25 | Error "function" (!(" does not exist").)+:table " does not exist"
26 => [[ table >string <sql-function-missing> ]]
29 Error "syntax error at end of input":error
30 => [[ error >string <sql-syntax-error> ]]
31 | Error "syntax error at or near " .+:syntaxerror
32 => [[ syntaxerror >string unquote <sql-syntax-error> ]]
34 UnknownError = .* => [[ >string <sql-unknown-error> ]]
36 PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError)
41 TUPLE: parse-postgresql-location column line text ;
42 C: <parse-postgresql-location> parse-postgresql-location
44 EBNF: parse-postgresql-line-error [=[
46 Line = "LINE " [0-9]+:line ": " .+:sql
47 => [[ f line >string string>number sql >string <parse-postgresql-location> ]]
51 :: set-caret-position ( error caret-line -- error )
53 error line>> number>string length "LINE : " length +
54 - [ error ] dip >>column ;
56 : postgresql-location ( line column -- obj )
57 [ parse-postgresql-line-error ] dip