String operator = this.operator;
String value = this.value;
if (editorForm != null && !editorForm.isDisposed()) {
conditionOperator = editorForm.getSelectedOperator();
DBColumn selectedColumn = editorForm.getSelectedColumn();
if (selectedColumn != null) {
columnName = selectedColumn.getName();
operator = conditionOperator == null ? " " : conditionOperator.getText();
value = editorForm.getValue();
}
}
DBColumn column = dataset.getColumn(columnName);
if (conditionOperator != null &&
conditionOperator.getValuePrefix() != null &&
conditionOperator.getValuePostfix() != null) {
value = conditionOperator.getValuePrefix() + value + conditionOperator.getValuePostfix();
}
else if (StringUtil.isNotEmptyOrSpaces(value)) {
DBDataType dataType = column == null ? null : column.getDataType();
if (dataType != null && dataType.isNative()) {
ConnectionHandler connectionHandler = dataset.getConnectionHandler();
RegionalSettings regionalSettings = RegionalSettings.getInstance(connectionHandler.getProject());
GenericDataType genericDataType = dataType.getNativeDataType().getBasicDataType();
if (genericDataType == GenericDataType.LITERAL) {
value = com.intellij.openapi.util.text.StringUtil.replace(value, "'", "''");
value = "'" + value + "'";
} else if (genericDataType == GenericDataType.DATE_TIME) {
DatabaseMetadataInterface metadataInterface = connectionHandler.getInterfaceProvider().getMetadataInterface();
try {
Date date = regionalSettings.getFormatter().parseDateTime(value);
value = metadataInterface.createDateString(date);
} catch (ParseException e) {
try {
Date date = regionalSettings.getFormatter().parseDate(value);
value = metadataInterface.createDateString(date);
} catch (ParseException e1) {
// value can be something like "sysdate" => not parseable
//e1.printStackTrace();
}
}
} else if (genericDataType == GenericDataType.NUMERIC) {
/*try {
regionalSettings.getFormatter().parseNumber(value);
} catch (ParseException e) {
e.printStackTrace();
}*/
}
}
}
buffer.append(column == null ? columnName : column.getQuotedName(false));
buffer.append(" ");
buffer.append(operator);
buffer.append(" ");
buffer.append(value);
}