From 655797ff34f99533cd1abfbbf096e6e466c9615c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= <bjourne@gmail.com>
Date: Tue, 30 Sep 2014 14:53:22 +0200
Subject: [PATCH] db.postgresql: ensure that 2 line error messages are handled

---
 basis/db/postgresql/postgresql-tests.factor | 20 ++++++++++++++++----
 basis/db/postgresql/postgresql.factor       |  2 +-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/basis/db/postgresql/postgresql-tests.factor b/basis/db/postgresql/postgresql-tests.factor
index 04348f44cb..ce13ab2b9c 100644
--- a/basis/db/postgresql/postgresql-tests.factor
+++ b/basis/db/postgresql/postgresql-tests.factor
@@ -1,6 +1,6 @@
-USING: accessors alien continuations db db.queries db.postgresql db.private
-db.tester db.tuples db.types io classes kernel math namespaces prettyprint
-sequences system tools.test unicode.case ;
+USING: accessors alien continuations db db.errors db.queries db.postgresql
+db.private db.tester db.tuples db.types io classes kernel math namespaces
+prettyprint sequences system tools.test unicode.case ;
 IN: db.postgresql.tests
 
 : nonexistant-db ( -- db )
@@ -16,7 +16,19 @@ IN: db.postgresql.tests
 ] unit-test
 
 ! Ensure the test database exists
-[ ] [ postgresql-test-db [ ] with-db ] unit-test
+postgresql-template1-db [
+    postgresql-test-db-name ensure-database
+] with-db
+
+! Triggers a two line error message (ERROR + DETAIL) because two
+! connections can't simultaneously use the template1 database.
+[
+    postgresql-template1-db [
+        postgresql-template1-db [
+            "will_never_exist" ensure-database
+        ] with-db
+    ] with-db
+] [ sql-unknown-error? ] must-fail-with
 
 [ ] [
     postgresql-test-db [
diff --git a/basis/db/postgresql/postgresql.factor b/basis/db/postgresql/postgresql.factor
index a002175ea8..12acded9c0 100644
--- a/basis/db/postgresql/postgresql.factor
+++ b/basis/db/postgresql/postgresql.factor
@@ -284,10 +284,10 @@ M: postgresql-db-connection compound ( string object -- string' )
 M: postgresql-db-connection parse-db-error
     "\n" split dup length {
         { 1 [ first parse-postgresql-sql-error ] }
+        { 2 [ concat parse-postgresql-sql-error ] }
         { 3 [
                 first3
                 [ parse-postgresql-sql-error ] 2dip
                 postgresql-location >>location
         ] }
     } case ;
-