From 48cfa0fbdf4d8d198562b7cb3efec46c8085f783 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 18 Feb 2014 11:41:11 +0100 Subject: [PATCH] runtime: Fix unique constraint error checks The sqlite3 version in fedora (3.8) returns a different error string in the unique constraints failure case than the one in hack/ (3.7). This updates the check to detect both, fixing one integration check failure on Fedora. Docker-DCO-1.1-Signed-off-by: Alexander Larsson (github: alexlarsson) --- graphdb/graphdb.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/graphdb/graphdb.go b/graphdb/graphdb.go index 9e2466b..46a23b1 100644 --- a/graphdb/graphdb.go +++ b/graphdb/graphdb.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" "path" + "strings" "sync" ) @@ -51,6 +52,21 @@ type Database struct { mux sync.RWMutex } +func IsNonUniqueNameError(err error) bool { + str := err.Error() + // sqlite 3.7.17-1ubuntu1 returns: + // Set failure: Abort due to constraint violation: columns parent_id, name are not unique + if strings.HasSuffix(str, "name are not unique") { + return true + } + // sqlite-3.8.3-1.fc20 returns: + // Set failure: Abort due to constraint violation: UNIQUE constraint failed: edge.parent_id, edge.name + if strings.Contains(str, "UNIQUE constraint failed") && strings.Contains(str, "edge.name") { + return true + } + return false +} + // Create a new graph database initialized with a root entity func NewDatabase(conn *sql.DB, init bool) (*Database, error) { if conn == nil {