}
else {
attrMask.setInt(attrMask.getInt()|SqlQuery.ATTRTYPE_DB);
}
if (this.getOperation() == BusinessQuery.OP_SELECT) {
result.replaceParameters("t%1.%2", new IntegerData(t), c);
}
else {
result.concat(c);
tableIndex.setInt(t);
}
}
else if (node instanceof ConstraintConstant) {
result.setValue( ((ConstraintConstant)node).getValue() );
}
else if (node instanceof ConstraintOperation) {
opNodeOp = ((ConstraintOperation)node).getOperation();
opNodeOpCode = opNodeOp&ConstraintOperation.OPCODE_MASK;
if (opNodeOpCode == ConstraintOperation.OPCODE_IN) {
if (stack.size() < 2) {
throw new Error(Error.QC_CONSTRAINT_STACK_EMPTY, "GetWhereText", this).getException();
}
result.setValue( "(" );
if (!(stack.get(stack.size()-1) instanceof ConstraintAttr)) {
throw new Error(Error.QC_NEED_ATTR_NODE, "GetWhereText", this).getException();
}
else {
// -----------------------------------
// Parameters for call to GetWhereText
// -----------------------------------
ParameterHolder_integer qq_attrMask = new ParameterHolder_integer(attrMask.getInt());
ParameterHolder_integer qq_valueCount = new ParameterHolder_integer(valueCount.getInt());
ParameterHolder_integer qq_tableIndex = new ParameterHolder_integer(tableIndex.getInt());
TextData qq_GetWhereText = this.getWhereText(stack, qq_attrMask, qq_valueCount, qq_tableIndex);
attrMask.setInt(qq_attrMask.getInt());
valueCount.setInt(qq_valueCount.getInt());
tableIndex.setInt(qq_tableIndex.getInt());
c = qq_GetWhereText;
}
while (stack.size() > 1 && stack.get(stack.size()-1) instanceof ConstraintAttr) {
c.replaceRange(", ", 0, 0);
// -----------------------------------
// Parameters for call to GetWhereText
// -----------------------------------
ParameterHolder_integer qq_attrMask = new ParameterHolder_integer(attrMask.getInt());
ParameterHolder_integer qq_valueCount = new ParameterHolder_integer(valueCount.getInt());
ParameterHolder_integer qq_tableIndex = new ParameterHolder_integer(tableIndex.getInt());
TextData qq_GetWhereText = this.getWhereText(stack, qq_attrMask, qq_valueCount, qq_tableIndex);
attrMask.setInt(qq_attrMask.getInt());
valueCount.setInt(qq_valueCount.getInt());
tableIndex.setInt(qq_tableIndex.getInt());
c.replaceRange(qq_GetWhereText, 0, 0);
}
result.concat(c);
result.concat(") in (");
if (!(stack.get(stack.size()-1) instanceof ConstraintValue)) {
throw new Error(Error.QC_NEED_VALUE_NODE, "GetWhereText", this).getException();
}
else {
result.concat(((ConstraintValue)(stack.get(stack.size()-1))).getValue());
stack.deleteRow(stack.size()- 1);
}
result.concat(")");
if (stack.size() > 0 && stack.get(stack.size()-1) instanceof ConstraintSqlData) {
Array_Of_DataValue<DataValue> qq_localVector = ((ConstraintSqlData)(stack.get(stack.size()-1))).getData().getValues();
if (qq_localVector != null) {
for (DataValue d : qq_localVector) {
this.getData().get(tableIndex.getInt()-1).getValues().add(d);
}
}
stack.deleteRow(stack.size()- 1);
}
}
else if (opNodeOpCode == ConstraintOperation.OPCODE_LEFTJOIN || opNodeOpCode == ConstraintOperation.OPCODE_RIGHTJOIN || opNodeOpCode == ConstraintOperation.OPCODE_EQUIJOIN) {
boolean doFancyJoin = opNodeOpCode != ConstraintOperation.OPCODE_EQUIJOIN && this.getDBSession().getDBVendorType() != Constants.DB_VT_ORACLE && this.getDBSession().getDBVendorType() != Constants.DB_VT_SYBASE;
int oldFromTable = 0, newFromTable = 0, oldToTable = 0, newToTable = 0;
if (opNodeOpCode == ConstraintOperation.OPCODE_EQUIJOIN) {
this.setOptions(this.getOptions()|SqlQuery.OPT_INNER_JOIN);
}
else {
this.setOptions(this.getOptions()|SqlQuery.OPT_OUTER_JOIN);
}
TextData c3 = new TextData();
if (doFancyJoin) {
node = stack.get(stack.size()-1);
if (!(node instanceof ConstraintAttr)) {
throw new Error(Error.QC_NEED_ATTR_NODE, "GetWhereText", this).getException();
}
attrNode = (ConstraintAttr)node;
if (attrNode.getTableIndex() > this.tableList.size()) {
throw new Error(Error.QC_ILLEGAL_TABLE_INDEX, "GetWhereText", this, new IntegerData(attrNode.getTableIndex()), new IntegerData(this.tableList.size())).getException();
}
node = stack.get(stack.size()-1-1);
if (!(node instanceof ConstraintAttr)) {
throw new Error(Error.QC_NEED_ATTR_NODE, "GetWhereText", this).getException();
}
if (((ConstraintAttr)node).getTableIndex() > this.tableList.size()) {
throw new Error(Error.QC_ILLEGAL_TABLE_INDEX, "GetWhereText", this, new IntegerData(attrNode.getTableIndex()), new IntegerData(this.tableList.size())).getException();
}
t = attrNode.getEntity().getTableAliases().get(attrNode.getTableIndex()-1).getValue();
int t2 = ((ConstraintAttr)node).getEntity().getTableAliases().get(((ConstraintAttr)node).getTableIndex()-1).getValue();
//
// We want to put in a join for attrNode. We know the table
// aliases t, and t2 to use. We have to check that these
// tables aren't already participating in a join. If either of
// them are then we will have to make a new table alias for that
// table and put in an addtional equijoin between the old alias
// and the new based, of course, on the key columns. The one
// exception is that t can participate in multiple joins if
// the OPT_NO_MULT_OUTER_JOIN option is not set.
//
int t3 = 0;
if (this.tableList.get(t2-1).getPrevTable() != null) {
oldToTable = t2;
this.addTable(this.tableList.get(t2-1).getTableName());
for (int i = 1; i <= attrNode.getEntity().getNumKeyAttrs(); i++) {
t3 = attrNode.getTableIndex();
// ------------------------------------
// Parameters for call to GetColumnName
// ------------------------------------
ParameterHolder_integer qq_tableIndex = new ParameterHolder_integer(t3);
ParameterHolder_TextData qq_columnName = new ParameterHolder_TextData();
attrNode.getEntity().getColumnName(i, qq_tableIndex, qq_columnName);
t3 = qq_tableIndex.getInt();
c = (TextData)qq_columnName.getObject();
if (c == null) {
c = new TextData();
}
this.addConstraint(c3.replaceParameters("t%1.%2 = t%3.%2", new IntegerData(t2), c, this.getNumTables()).toString());
}
t2 = this.getNumTables().getValue();
newToTable = t2;
}
if (this.tableList.get(t-1).getNextTable() == null) {
this.tableList.get(t-1).setNextTable(new Array_Of_SqlQueryTable<SqlQueryTable>());
this.tableList.get(t-1).getNextTable().add(this.tableList.get(t2-1));
this.tableList.get(t2-1).setPrevTable(this.tableList.get(t-1));
}
else if ((this.getOptions()&SqlQuery.OPT_NO_MULT_OUTER_JOIN) == 0) {
this.tableList.get(t-1).getNextTable().add(this.tableList.get(t2-1));
this.tableList.get(t2-1).setPrevTable(this.tableList.get(t-1));
}
else {
oldFromTable = t;
this.addTable(this.tableList.get(t-1).getTableName());
for (int i = 1; i <= attrNode.getEntity().getNumKeyAttrs(); i++) {
t3 = attrNode.getTableIndex();
// ------------------------------------
// Parameters for call to GetColumnName
// ------------------------------------
ParameterHolder_integer qq_tableIndex = new ParameterHolder_integer(t3);
ParameterHolder_TextData qq_columnName = new ParameterHolder_TextData();
attrNode.getEntity().getColumnName(i, qq_tableIndex, qq_columnName);
t3 = qq_tableIndex.getInt();
c = (TextData)qq_columnName.getObject();
if (c == null) {
c = new TextData();
}
this.addConstraint(c3.replaceParameters("t%1.%2 = t%3.%2", new IntegerData(t), c, this.getNumTables()).toString());
}
t = this.getNumTables().getValue();
newFromTable = t;
this.tableList.get(t-1).setNextTable(new Array_Of_SqlQueryTable<SqlQueryTable>());
this.tableList.get(t-1).getNextTable().add(this.tableList.get(t2-1));
this.tableList.get(t2-1).setPrevTable(this.tableList.get(t-1));
}
this.tableList.get(t-1).setJoinOp(opNodeOpCode);
if (this.getDBSession().getDBVendorType() != Constants.DB_VT_INFORMIX) {
this.tableList.get(t2-1).setOnClause(result);
}
}
//
// We've now completed linking the joined tables together in the
// table list. Now we need to create the join condition. Depending
// on the database this may end up in the where clause or in the
// join clause.
//
int params = (opNodeOp&ConstraintOperation.PCOUNT_MASK)/ConstraintOperation.PCOUNT_INCREMENT;
if (stack.size() < params*2) {
throw new Error(Error.QC_CONSTRAINT_STACK_EMPTY, "GetWhereText", this).getException();
}
int format = this.operationFormat(opNodeOp);
if (doFancyJoin) {
c2 = new TextData(" = ");
}
else {
c2 = this.infixOperator(opNodeOp, 1);
}
for (int i = 1; i <= params*2; i++) {
if (i > 1) {
if ((i&1) > 0) {
result.concat(" and ");
}
else {
result.concat(c2);
}
}
node = stack.get(stack.size()-1);
if (!(node instanceof ConstraintAttr)) {
throw new Error(Error.QC_NEED_ATTR_NODE, "GetWhereText", this).getException();
}
stack.deleteRow(stack.size()- 1);
attrNode = (ConstraintAttr)node;
t = attrNode.getTableIndex();
// ------------------------------------
// Parameters for call to GetColumnName
// ------------------------------------
ParameterHolder_integer qq_tableIndex = new ParameterHolder_integer(t);
ParameterHolder_TextData qq_columnName = new ParameterHolder_TextData();
attrNode.getEntity().getColumnName(attrNode.getAttr(), qq_tableIndex, qq_columnName);
t = qq_tableIndex.getInt();
c = (TextData)qq_columnName.getObject();
if (t == oldFromTable) {
t = newFromTable;
}
else if (t == oldToTable) {
t = newToTable;
}
if (c == null) {
c = new TextData();
}
result.concat(c3.replaceParameters("t%1.%2", new IntegerData(t), c));
if ((i&1) == 0 && (format&SqlQuery.OP_POSTFIX_MASK) > 0) {
result.concat(this.postfixOperator(opNodeOp));
}
}
if (doFancyJoin && this.getDBSession().getDBVendorType() != Constants.DB_VT_INFORMIX) {