use of com.developmentontheedge.sql.model.AstStringPart in project be5 by DevelopmentOnTheEdge.
the class DB2Transformer method transformString.
@Override
protected void transformString(AstStringConstant string) {
for (AstStringPart child : string.children().select(AstStringPart.class)) {
String content = child.getContent().replace("\\'", "''");
child.setContent(string.isEscape() ? content.replaceAll("\\\\([^bfnrt])", "$1") : content, true);
}
if (string.isEscape()) {
string.setEscape(false);
AstConcatExpression concat = new AstConcatExpression(SqlParserTreeConstants.JJTCONCATEXPRESSION);
if (replacedEscapes(string, concat))
string.replaceWith(concat);
}
}
use of com.developmentontheedge.sql.model.AstStringPart in project be5 by DevelopmentOnTheEdge.
the class DB2Transformer method replacedEscapes.
private boolean replacedEscapes(AstStringConstant string, AstConcatExpression concat) {
boolean find = false;
for (int i = 0; i < string.jjtGetNumChildren(); i++) {
if (string.child(i) instanceof AstStringPart) {
AstStringPart child = (AstStringPart) string.child(i);
Matcher matcher = Pattern.compile("\\\\([bfnrt])").matcher(child.getContent());
while (matcher.find()) {
find = true;
StringBuffer buffer = new StringBuffer();
matcher.appendReplacement(buffer, "");
for (int j = 0; j < i; j++) {
getLastString(concat).addChild(string.child(j));
}
if (!"".equals(buffer.toString()))
getLastString(concat).addChild(new AstStringPart(buffer.toString(), true));
concat.addChild(parserContext.getFunction("CHR").node(AstNumericConstant.of(AstStringConstant.getASCII(matcher.group(1).charAt(0)))));
}
if (find) {
String tail = matcher.appendTail(new StringBuffer()).toString();
if (!"".equals(tail))
getLastString(concat).addChild(new AstStringPart(tail));
string.removeChild(child);
}
}
}
return find;
}
use of com.developmentontheedge.sql.model.AstStringPart in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method replacedEscapes.
private boolean replacedEscapes(AstStringConstant string, AstConcatExpression concat) {
boolean find = false;
for (int i = 0; i < string.jjtGetNumChildren(); i++) {
if (string.child(i) instanceof AstStringPart) {
AstStringPart child = (AstStringPart) string.child(i);
Matcher matcher = Pattern.compile("\\\\([bfnrt])").matcher(child.getContent());
while (matcher.find()) {
find = true;
StringBuffer buffer = new StringBuffer();
matcher.appendReplacement(buffer, "");
for (int j = 0; j < i; j++) {
getLastString(concat).addChild(string.child(j));
}
if (!"".equals(buffer.toString()))
getLastString(concat).addChild(new AstStringPart(buffer.toString(), true));
concat.addChild(parserContext.getFunction("CHR").node(AstNumericConstant.of(AstStringConstant.getASCII(matcher.group(1).charAt(0)))));
}
if (find) {
String tail = matcher.appendTail(new StringBuffer()).toString();
if (!"".equals(tail))
getLastString(concat).addChild(new AstStringPart(tail));
string.removeChild(child);
}
}
}
return find;
}
use of com.developmentontheedge.sql.model.AstStringPart in project be5 by DevelopmentOnTheEdge.
the class ContextApplier method applySessionTag.
private void applySessionTag(AstBeSessionTag child) {
String name = child.getName();
Object value = context.getSessionVariable(name);
if (value == null) {
if (child.getDefault() != null) {
value = SqlTypeUtils.parseValue(child.getDefault(), child.getType());
} else {
value = "";
}
}
SimpleNode replacement;
// TODO: support refColumn; smart quoting - in server module
if (child.jjtGetParent() instanceof AstStringConstant) {
replacement = new AstStringPart(value.toString());
} else {
if (SqlTypeUtils.isNumber(value.getClass())) {
replacement = AstNumericConstant.of((Number) value);
} else {
replacement = new AstStringConstant(value.toString());
}
}
child.replaceWith(replacement);
}
use of com.developmentontheedge.sql.model.AstStringPart in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method transformString.
@Override
protected void transformString(AstStringConstant string) {
for (AstStringPart child : string.children().select(AstStringPart.class)) {
String content = child.getContent().replace("\\'", "''");
child.setContent(string.isEscape() ? content.replaceAll("\\\\([^bfnrt])", "$1") : content, true);
}
if (string.isEscape()) {
string.setEscape(false);
AstConcatExpression concat = new AstConcatExpression(SqlParserTreeConstants.JJTCONCATEXPRESSION);
if (replacedEscapes(string, concat))
string.replaceWith(concat);
}
}
Aggregations