提交 7efe8087 authored 作者: Thomas Mueller's avatar Thomas Mueller

In error messages about referential constraint violation, the values are now included.

上级 86e275b4
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>SCRIPT and RUNSCRIPT: the password can now be set using a prepared statement.
<ul><li>In error messages about referential constraint violation, the values are now included.
</li><li>SCRIPT and RUNSCRIPT: the password can now be set using a prepared statement.
Previously, it was required to be a literal in the SQL statement.
</li><li>MySQL compatibility: SUBSTR with a negative start index now works like MySQL.
</li><li>When enabling autocommit, the transaction is now committed (as required by the JDBC API).
......
......@@ -167,9 +167,11 @@ public class ConstraintReferential extends Constraint {
* Get a short description of the constraint. This includes the constraint
* name (if set), and the constraint expression.
*
* @param searchIndex the index, or null
* @param check the row, or null
* @return the description
*/
private String getShortDescription() {
private String getShortDescription(Index searchIndex, SearchRow check) {
StatementBuilder buff = new StatementBuilder(getName());
buff.append(": ").append(table.getSQL()).append(" FOREIGN KEY(");
for (IndexColumn c : columns) {
......@@ -182,7 +184,21 @@ public class ConstraintReferential extends Constraint {
buff.appendExceptFirst(", ");
buff.append(r.getSQL());
}
return buff.append(')').toString();
buff.append(')');
if (searchIndex != null && check != null) {
buff.append(" (");
buff.resetCount();
Column[] cols = searchIndex.getColumns();
int len = Math.min(columns.length, cols.length);
for (int i = 0; i < len; i++) {
int idx = cols[i].getColumnId();
Value c = check.getValue(idx);
buff.appendExceptFirst(", ");
buff.append(c == null ? "" : c.toString());
}
buff.append(')');
}
return buff.toString();
}
public String getCreateSQLWithoutIndexes() {
......@@ -343,7 +359,7 @@ public class ConstraintReferential extends Constraint {
}
if (!existsRow(session, refIndex, check, null)) {
throw DbException.get(ErrorCode.REFERENTIAL_INTEGRITY_VIOLATED_PARENT_MISSING_1,
getShortDescription());
getShortDescription(refIndex, check));
}
}
......@@ -396,7 +412,7 @@ public class ConstraintReferential extends Constraint {
Row excluding = (refTable == table) ? oldRow : null;
if (existsRow(session, index, check, excluding)) {
throw DbException.get(ErrorCode.REFERENTIAL_INTEGRITY_VIOLATED_CHILD_EXISTS_1,
getShortDescription());
getShortDescription(index, check));
}
}
......@@ -638,7 +654,7 @@ public class ConstraintReferential extends Constraint {
ResultInterface r = session.prepare(sql).query(1);
if (r.next()) {
throw DbException.get(ErrorCode.REFERENTIAL_INTEGRITY_VIOLATED_PARENT_MISSING_1,
getShortDescription());
getShortDescription(null, null));
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论