/** * Parses the constraint as a SQL Where-clause item */ //@Override public String toSql(bool?includeSchemaInColumnPaths) { if (_expression != null) { return(_expression); } StringBuilder sb = new StringBuilder(); if (_childItems == null) { sb.Append(_selectItem.getSameQueryAlias(includeSchemaInColumnPaths)); if (_operand == null && _operator == OperatorType.EQUALS_TO) { sb.Append(" IS NULL"); } else if (_operand == null && _operator == OperatorType.DIFFERENT_FROM) { sb.Append(" IS NOT NULL"); } else { object operand = appendOperator(sb, _operand, _operator); if (operand is SelectItem) { String selectItemString = ((SelectItem)operand) .getSameQueryAlias(includeSchemaInColumnPaths); sb.Append(selectItemString); } else { ColumnType columnType = _selectItem.getExpectedColumnType(); string sqlValue = ""; // FormatHelper.formatSqlValue(columnType, operand); sb.Append(sqlValue); } } } else { sb.Append('('); for (int i = 0; i < _childItems.Count; i++) { FilterItem item = _childItems[i]; if (i != 0) { sb.Append(' '); sb.Append(_logicalOperator.ToString()); sb.Append(' '); } sb.Append(item.toSql()); } sb.Append(')'); } return(sb.ToString()); }
} // select() protected object createOperand(string token, SelectItem leftSelectItem, bool searchSelectItems) { if (token.Equals("NULL", StringComparison.CurrentCultureIgnoreCase)) { return(null); } if (token.StartsWith("'") && token.EndsWith("'") && token.Length > 2) { string stringOperand = token.Substring(1, token.Length - 1); //[J2N] replaceAll <=> Replace stringOperand = stringOperand.Replace("\\\\'", "'"); return(stringOperand); } if (searchSelectItems) { SelectItem selectItem = findSelectItem(token, false); if (selectItem != null) { return(selectItem); } } ColumnType expectedColumnType = leftSelectItem.getExpectedColumnType(); object result = null; if (expectedColumnType == null) { // We're assuming number here, but it could also be boolean or a // time based type. But anyways, this should not happen since // expected column type should be available. result = NumberComparator.toNumber(token); } else if (expectedColumnType.isBoolean()) { result = BooleanComparator.toBoolean(token); } // else if (expectedColumnType.isTimeBased()) // { // result = FormatHelper.parseSqlTime(expectedColumnType, token); // } // else // { // result = NumberComparator.toNumber(token); // } // if (result == null) // { // // shouldn't happen since only "NULL" is parsed as null. // throw new QueryParserException("Could not parse operand: " + token); // } return(result); } // createOperand()
} // getColumn() /** * Tries to infer the {@link ColumnType} of this {@link SelectItem}. For * expression based select items, this is not possible, and the method will * return null. * * @return */ public ColumnType getExpectedColumnType() { if (_subQuerySelectItem != null) { return(_subQuerySelectItem.getExpectedColumnType()); } if (_function != null) { if (_column != null) { return(_function.getExpectedColumnType(_column.getType())); } else { return(_function.getExpectedColumnType(null)); } } if (_column != null) { return(_column.getType()); } return(null); } // getExpectedColumnType()