public String getSQL() { StringBuffer localStringBuffer = new StringBuffer(); switch (getConstraintType()) { case 4: if ((getMainColumns().length > 1) || ((getMainColumns().length == 1) && (!getName().isReservedName()))) { if (!getName().isReservedName()) { localStringBuffer.append("CONSTRAINT").append(' '); localStringBuffer.append(getName().statementName).append(' '); } localStringBuffer.append("PRIMARY").append(' ').append("KEY"); localStringBuffer.append( getMain().getColumnListSQL(getMainColumns(), getMainColumns().length)); } break; case 2: if (!getName().isReservedName()) { localStringBuffer.append("CONSTRAINT").append(' '); localStringBuffer.append(getName().statementName); localStringBuffer.append(' '); } localStringBuffer.append("UNIQUE"); int[] arrayOfInt = getMainColumns(); localStringBuffer.append(getMain().getColumnListSQL(arrayOfInt, arrayOfInt.length)); break; case 0: if (this.isForward) { localStringBuffer.append("ALTER").append(' ').append("TABLE").append(' '); localStringBuffer.append(getRef().getName().getSchemaQualifiedStatementName()); localStringBuffer.append(' ').append("ADD").append(' '); getFKStatement(localStringBuffer); } else { getFKStatement(localStringBuffer); } break; case 3: if (!isNotNull()) { if (!getName().isReservedName()) { localStringBuffer.append("CONSTRAINT").append(' '); localStringBuffer.append(getName().statementName).append(' '); } localStringBuffer.append("CHECK").append('('); localStringBuffer.append(this.check.getSQL()); localStringBuffer.append(')'); } break; case 1: } return localStringBuffer.toString(); }
public String getSQL() { StringBuffer sb = new StringBuffer(); switch (getConstraintType()) { case Constraint.PRIMARY_KEY: if (getMainColumns().length > 1 || (getMainColumns().length == 1 && !getName().isReservedName())) { if (!getName().isReservedName()) { sb.append(Tokens.T_CONSTRAINT).append(' '); sb.append(getName().statementName).append(' '); } sb.append(Tokens.T_PRIMARY).append(' ').append(Tokens.T_KEY); getColumnList(getMain(), getMainColumns(), getMainColumns().length, sb); } break; case Constraint.UNIQUE: if (!getName().isReservedName()) { sb.append(Tokens.T_CONSTRAINT).append(' '); sb.append(getName().statementName); sb.append(' '); } sb.append(Tokens.T_UNIQUE); int[] col = getMainColumns(); getColumnList(getMain(), col, col.length, sb); break; case Constraint.FOREIGN_KEY: if (isForward) { sb.append(Tokens.T_ALTER).append(' ').append(Tokens.T_TABLE).append(' '); sb.append(getRef().getName().getSchemaQualifiedStatementName()); sb.append(' ').append(Tokens.T_ADD).append(' '); getFKStatement(sb); } else { getFKStatement(sb); } break; case Constraint.CHECK: if (isNotNull()) { break; } if (!getName().isReservedName()) { sb.append(Tokens.T_CONSTRAINT).append(' '); sb.append(getName().statementName).append(' '); } sb.append(Tokens.T_CHECK).append('('); sb.append(check.getSQL()); sb.append(')'); // should not throw as it is already tested OK break; } return sb.toString(); }