Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs122-19wi
nanodb-base
Commits
726cbe18
Commit
726cbe18
authored
6 years ago
by
Donald H. (Donnie) Pinkston, III
Browse files
Options
Download
Email Patches
Plain Diff
More detailed errors when constraint enforcement fails
parent
69f0be2a
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/edu/caltech/nanodb/relations/DatabaseConstraintEnforcer.java
+12
-10
.../caltech/nanodb/relations/DatabaseConstraintEnforcer.java
with
12 additions
and
10 deletions
+12
-10
src/main/java/edu/caltech/nanodb/relations/DatabaseConstraintEnforcer.java
View file @
726cbe18
...
...
@@ -112,8 +112,8 @@ public class DatabaseConstraintEnforcer implements RowEventListener {
List
<
KeyColumnRefs
>
candKeyList
=
schema
.
getCandidateKeys
();
for
(
KeyColumnRefs
candKey
:
candKeyList
)
{
if
(
hasCandidateKeyValue
(
tableInfo
,
candKey
,
newTuple
))
{
String
msg
=
makeErrorMessage
(
"Cannot insert tuple
due to unique constraint"
,
String
msg
=
makeErrorMessage
(
"Cannot insert tuple "
+
newTuple
+
"
due to unique constraint"
,
candKey
.
getConstraintName
());
throw
new
ConstraintViolationException
(
msg
);
...
...
@@ -125,8 +125,8 @@ public class DatabaseConstraintEnforcer implements RowEventListener {
List
<
ForeignKeyColumnRefs
>
foreignKeys
=
schema
.
getForeignKeys
();
for
(
ForeignKeyColumnRefs
foreignKey
:
foreignKeys
)
{
if
(!
referencedTableHasValue
(
foreignKey
,
newTuple
))
{
String
msg
=
makeErrorMessage
(
"Cannot insert tuple
due to foreign key constraint"
,
String
msg
=
makeErrorMessage
(
"Cannot insert tuple "
+
newTuple
+
"
due to foreign key constraint"
,
foreignKey
.
getConstraintName
());
throw
new
ConstraintViolationException
(
msg
);
...
...
@@ -388,9 +388,10 @@ public class DatabaseConstraintEnforcer implements RowEventListener {
if
(
existsOp
.
evaluatePredicate
(
null
))
{
throw
new
ConstraintViolationException
(
String
.
format
(
"Cannot update tuple on table %s due to ON UPDATE "
+
"RESTRICT constraint %s from referencing table %s"
,
tableName
,
fk
.
getConstraintName
(),
referencingTableName
));
"Cannot update tuple %s on table %s due to "
+
"ON UPDATE RESTRICT constraint %s from "
+
"referencing table %s"
,
oldTuple
,
tableName
,
fk
.
getConstraintName
(),
referencingTableName
));
}
}
break
;
...
...
@@ -460,9 +461,10 @@ public class DatabaseConstraintEnforcer implements RowEventListener {
if
(
existsOp
.
evaluatePredicate
(
null
))
{
throw
new
ConstraintViolationException
(
String
.
format
(
"Cannot delete tuple on table %s due to ON DELETE "
+
"RESTRICT constraint %s from referencing table %s"
,
tableName
,
fk
.
getConstraintName
(),
referencingTableName
));
"Cannot delete tuple %s on table %s due to "
+
"ON DELETE RESTRICT constraint %s from "
+
"referencing table %s"
,
oldTuple
,
tableName
,
fk
.
getConstraintName
(),
referencingTableName
));
}
}
break
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help