1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors db.errors kernel math math.parser multiline
4 peg.ebnf quoting sequences strings ;
5 IN: db.postgresql.errors
7 EBNF: parse-postgresql-sql-error [=[
12 Error ("relation "|"table ")(!(" already exists").)+:table " already exists"
13 => [[ table >string unquote <sql-table-exists> ]]
14 | Error ("relation "|"table ")(!(" does not exist").)+:table " does not exist"
15 => [[ table >string unquote <sql-table-missing> ]]
18 Error ("database")(!(" already exists").)+:database " already exists"
19 => [[ database >string <sql-database-exists> ]]
22 Error "function" (!(" already exists").)+:table " already exists"
23 => [[ table >string <sql-function-exists> ]]
24 | Error "function" (!(" does not exist").)+:table " does not exist"
25 => [[ table >string <sql-function-missing> ]]
28 Error "syntax error at end of input":error
29 => [[ error >string <sql-syntax-error> ]]
30 | Error "syntax error at or near " .+:syntaxerror
31 => [[ syntaxerror >string unquote <sql-syntax-error> ]]
33 UnknownError = .* => [[ >string <sql-unknown-error> ]]
35 PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError)
40 TUPLE: parse-postgresql-location column line text ;
41 C: <parse-postgresql-location> parse-postgresql-location
43 EBNF: parse-postgresql-line-error [=[
45 Line = "LINE " [0-9]+:line ": " .+:sql
46 => [[ f line >string string>number sql >string <parse-postgresql-location> ]]
50 :: set-caret-position ( error caret-line -- error )
52 error line>> number>string length "LINE : " length +
53 - [ error ] dip >>column ;
55 : postgresql-location ( line column -- obj )
56 [ parse-postgresql-line-error ] dip