ERROR: bad-schema ;
TUPLE: sql-unknown-error < sql-error message ;
+
: <sql-unknown-error> ( message -- error )
- \ sql-unknown-error new
- swap >>message ;
+ f swap sql-unknown-error boa ;
TUPLE: sql-table-exists < sql-error table ;
+
: <sql-table-exists> ( table -- error )
- \ sql-table-exists new
- swap >>table ;
+ f swap sql-table-exists boa ;
TUPLE: sql-table-missing < sql-error table ;
+
: <sql-table-missing> ( table -- error )
- \ sql-table-missing new
- swap >>table ;
+ f swap sql-table-missing boa ;
TUPLE: sql-syntax-error < sql-error message ;
+
: <sql-syntax-error> ( message -- error )
- \ sql-syntax-error new
- swap >>message ;
+ f swap sql-syntax-error boa ;
TUPLE: sql-function-exists < sql-error message ;
+
: <sql-function-exists> ( message -- error )
- \ sql-function-exists new
- swap >>message ;
+ f swap sql-function-exists boa ;
TUPLE: sql-function-missing < sql-error message ;
+
: <sql-function-missing> ( message -- error )
- \ sql-function-missing new
- swap >>message ;
+ f swap sql-function-missing boa ;
TUPLE: sql-database-exists < sql-error message ;
+
: <sql-database-exists> ( message -- error )
- \ sql-database-exists new
- swap >>message ;
+ f swap sql-database-exists boa ;
: ignore-error ( quot word -- )
- '[ dup _ execute [ drop ] [ rethrow ] if ] recover ; inline
+ '[ dup @ [ drop ] [ rethrow ] if ] recover ; inline
: ignore-table-exists ( quot -- )
- \ sql-table-exists? ignore-error ; inline
+ [ sql-table-exists? ] ignore-error ; inline
: ignore-table-missing ( quot -- )
- \ sql-table-missing? ignore-error ; inline
+ [ sql-table-missing? ] ignore-error ; inline
: ignore-function-exists ( quot -- )
- \ sql-function-exists? ignore-error ; inline
+ [ sql-function-exists? ] ignore-error ; inline
: ignore-function-missing ( quot -- )
- \ sql-function-missing? ignore-error ; inline
+ [ sql-function-missing? ] ignore-error ; inline
: ignore-database-exists ( quot -- )
- \ sql-database-exists? ignore-error ; inline
+ [ sql-database-exists? ] ignore-error ; inline
+++ /dev/null
-Doug Coleman
\ No newline at end of file
+++ /dev/null
-! Copyright (C) 2009 Doug Coleman.
-! 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 continuations ;
-IN: db.errors.postgresql.tests
-
-[
-
- [ "drop table foo;" sql-command ] ignore-errors
- [ "drop table ship;" sql-command ] ignore-errors
-
- [
- "insert into foo (id) values('1');" sql-command
- ] [
- { [ sql-table-missing? ] [ table>> "foo" = ] } 1&&
- ] must-fail-with
-
- [
- "create table ship(id integer);" sql-command
- "create table ship(id integer);" sql-command
- ] [
- { [ sql-table-exists? ] [ table>> "ship" = ] } 1&&
- ] must-fail-with
-
- [
- "create table foo(id) lol;" sql-command
- ] [
- sql-syntax-error?
- ] must-fail-with
-
-] test-postgresql
+++ /dev/null
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: kernel db.errors peg.ebnf strings sequences math
-combinators.short-circuit accessors math.parser quoting
-locals ;
-IN: db.errors.postgresql
-
-EBNF: parse-postgresql-sql-error
-
-Error = "ERROR:" [ ]+
-
-TableError =
- Error ("relation "|"table ")(!(" already exists").)+:table " already exists"
- => [[ table >string unquote <sql-table-exists> ]]
- | Error ("relation "|"table ")(!(" does not exist").)+:table " does not exist"
- => [[ table >string unquote <sql-table-missing> ]]
-
-DatabaseError =
- Error ("database")(!(" already exists").)+:database " already exists"
- => [[ database >string <sql-database-exists> ]]
-
-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> ]]
-
-UnknownError = .* => [[ >string <sql-unknown-error> ]]
-
-PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError)
-
-;EBNF
-
-
-TUPLE: parse-postgresql-location column line text ;
-C: <parse-postgresql-location> parse-postgresql-location
-
-EBNF: parse-postgresql-line-error
-
-Line = "LINE " [0-9]+:line ": " .+:sql
- => [[ f line >string string>number sql >string <parse-postgresql-location> ]]
-
-;EBNF
-
-:: set-caret-position ( error caret-line -- error )
- caret-line length
- error line>> number>string length "LINE : " length +
- - [ error ] dip >>column ;
-
-: postgresql-location ( line column -- obj )
- [ parse-postgresql-line-error ] dip
- set-caret-position ;
+++ /dev/null
-Doug Coleman
\ No newline at end of file
+++ /dev/null
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators.short-circuit db db.errors
-db.errors.sqlite db.sqlite io.files.temp io.files.unique kernel
-namespaces tools.test ;
-IN: db.errors.sqlite.tests
-
-[
- "sqlite" "error-test" [
-
- <sqlite-db> [
-
- [
- "insert into foo (id) values('1');" sql-command
- ] [
- { [ sql-table-missing? ] [ table>> "foo" = ] } 1&&
- ] must-fail-with
-
- "create table foo(id);" sql-command
-
- [
- "create table foo(id);" sql-command
- ] [
- { [ sql-table-exists? ] [ table>> "foo" = ] } 1&&
- ] must-fail-with
-
- ] with-db
- ] cleanup-unique-file
-] with-temp-directory
+++ /dev/null
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators db kernel sequences peg.ebnf
-strings db.errors ;
-IN: db.errors.sqlite
-
-TUPLE: unparsed-sqlite-error error ;
-C: <unparsed-sqlite-error> unparsed-sqlite-error
-
-SINGLETONS: table-exists table-missing ;
-
-: sqlite-table-error ( table message -- error )
- {
- { table-exists [ <sql-table-exists> ] }
- } case ;
-
-EBNF: parse-sqlite-sql-error
-
-TableMessage = " already exists" => [[ table-exists ]]
-
-SqliteError =
- "table " (!(TableMessage).)+:table TableMessage:message
- => [[ table >string message sqlite-table-error ]]
- | "no such table: " .+:table
- => [[ table >string <sql-table-missing> ]]
- | .*:error
- => [[ error >string <unparsed-sqlite-error> ]]
-;EBNF
--- /dev/null
+Doug Coleman
\ No newline at end of file
--- /dev/null
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors combinators.short-circuit db db.errors
+db.postgresql db.postgresql.errors io.files.unique kernel
+namespaces tools.test db.tester continuations ;
+
+[
+
+ [ "drop table foo;" sql-command ] ignore-errors
+ [ "drop table ship;" sql-command ] ignore-errors
+
+ [
+ "insert into foo (id) values('1');" sql-command
+ ] [
+ { [ sql-table-missing? ] [ table>> "foo" = ] } 1&&
+ ] must-fail-with
+
+ [
+ "create table ship(id integer);" sql-command
+ "create table ship(id integer);" sql-command
+ ] [
+ { [ sql-table-exists? ] [ table>> "ship" = ] } 1&&
+ ] must-fail-with
+
+ [
+ "create table foo(id) lol;" sql-command
+ ] [
+ sql-syntax-error?
+ ] must-fail-with
+
+] test-postgresql
--- /dev/null
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel db.errors peg.ebnf strings sequences math
+combinators.short-circuit accessors math.parser quoting
+locals ;
+IN: db.postgresql.errors
+
+EBNF: parse-postgresql-sql-error
+
+Error = "ERROR:" [ ]+
+
+TableError =
+ Error ("relation "|"table ")(!(" already exists").)+:table " already exists"
+ => [[ table >string unquote <sql-table-exists> ]]
+ | Error ("relation "|"table ")(!(" does not exist").)+:table " does not exist"
+ => [[ table >string unquote <sql-table-missing> ]]
+
+DatabaseError =
+ Error ("database")(!(" already exists").)+:database " already exists"
+ => [[ database >string <sql-database-exists> ]]
+
+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> ]]
+
+UnknownError = .* => [[ >string <sql-unknown-error> ]]
+
+PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError)
+
+;EBNF
+
+
+TUPLE: parse-postgresql-location column line text ;
+C: <parse-postgresql-location> parse-postgresql-location
+
+EBNF: parse-postgresql-line-error
+
+Line = "LINE " [0-9]+:line ": " .+:sql
+ => [[ f line >string string>number sql >string <parse-postgresql-location> ]]
+
+;EBNF
+
+:: set-caret-position ( error caret-line -- error )
+ caret-line length
+ error line>> number>string length "LINE : " length +
+ - [ error ] dip >>column ;
+
+: postgresql-location ( line column -- obj )
+ [ parse-postgresql-line-error ] dip
+ set-caret-position ;
! Copyright (C) 2007, 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: arrays assocs alien alien.syntax continuations io
-kernel math math.parser namespaces make prettyprint quotations
-sequences debugger db db.postgresql.lib db.postgresql.ffi
-db.tuples db.types tools.annotations math.ranges
-combinators classes classes.tuple locals words tools.walker
-db.private nmake accessors random db.queries destructors
-db.tuples.private db.postgresql db.errors.postgresql splitting ;
+USING: accessors classes.tuple combinators db
+db.postgresql.errors db.postgresql.ffi db.postgresql.lib
+db.private db.queries db.tuples db.tuples.private db.types
+destructors kernel make math math.parser namespaces nmake random
+sequences splitting ;
IN: db.postgresql
TUPLE: postgresql-db host port pgopts pgtty database username password ;
--- /dev/null
+Doug Coleman
\ No newline at end of file
--- /dev/null
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors combinators.short-circuit db db.errors
+db.sqlite db.sqlite.errors io.files.temp io.files.unique kernel
+namespaces tools.test ;
+
+[
+ "sqlite" "error-test" [
+
+ <sqlite-db> [
+
+ [
+ "insert into foo (id) values('1');" sql-command
+ ] [
+ { [ sql-table-missing? ] [ table>> "foo" = ] } 1&&
+ ] must-fail-with
+
+ "create table foo(id);" sql-command
+
+ [
+ "create table foo(id);" sql-command
+ ] [
+ { [ sql-table-exists? ] [ table>> "foo" = ] } 1&&
+ ] must-fail-with
+
+ ] with-db
+ ] cleanup-unique-file
+] with-temp-directory
--- /dev/null
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors combinators db kernel sequences peg.ebnf
+strings db.errors ;
+IN: db.sqlite.errors
+
+TUPLE: unparsed-sqlite-error error ;
+C: <unparsed-sqlite-error> unparsed-sqlite-error
+
+SINGLETONS: table-exists table-missing ;
+
+: sqlite-table-error ( table message -- error )
+ {
+ { table-exists [ <sql-table-exists> ] }
+ } case ;
+
+EBNF: parse-sqlite-sql-error
+
+TableMessage = " already exists" => [[ table-exists ]]
+
+SqliteError =
+ "table " (!(TableMessage).)+:table TableMessage:message
+ => [[ table >string message sqlite-table-error ]]
+ | "no such table: " .+:table
+ => [[ table >string <sql-table-missing> ]]
+ | .*:error
+ => [[ error >string <unparsed-sqlite-error> ]]
+;EBNF
! Copyright (C) 2005, 2008 Chris Double, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien arrays assocs classes compiler db hashtables
-io.files kernel math math.parser namespaces prettyprint fry
-sequences strings classes.tuple alien.c-types continuations
-db.sqlite.lib db.sqlite.ffi db.tuples words db.types combinators
-math.intervals io locals nmake accessors vectors math.ranges random
-math.bitwise db.queries destructors db.tuples.private interpolate
-io.streams.string make db.private sequences.deep
-db.errors.sqlite ;
+USING: accessors classes.tuple combinators db db.private
+db.queries db.sqlite.errors db.sqlite.ffi db.sqlite.lib
+db.tuples db.tuples.private db.types destructors interpolate
+kernel locals math math.parser namespaces nmake random sequences
+sequences.deep ;
IN: db.sqlite
TUPLE: sqlite-db path ;