mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
merge
This commit is contained in:
@@ -1177,7 +1177,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
String[] filterArray = filters.split("\\,");
|
||||
|
||||
for (String item : filterArray) {
|
||||
FilterManager.loadFilter(this.filters, item);
|
||||
FilterManager.loadFilter(this.filters, item.trim());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
public static ThreadLocal<Long> waitNanosLocal = new ThreadLocal<Long>();
|
||||
|
||||
private boolean logDiffrentThread = true;
|
||||
|
||||
public DruidDataSource(){
|
||||
this(false);
|
||||
}
|
||||
@@ -1128,7 +1130,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return;
|
||||
}
|
||||
|
||||
if (pooledConnection.getOwnerThread() != Thread.currentThread()) {
|
||||
if (logDiffrentThread && pooledConnection.getOwnerThread() != Thread.currentThread()) {
|
||||
LOG.warn("get/close not same thread");
|
||||
}
|
||||
|
||||
@@ -1569,6 +1571,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
value.setTestWhileIdle(this.isTestWhileIdle());
|
||||
|
||||
value.setDefaultAutoCommit(this.isDefaultAutoCommit());
|
||||
|
||||
if (defaultReadOnly != null) {
|
||||
value.setDefaultReadOnly(defaultReadOnly);
|
||||
}
|
||||
@@ -2395,4 +2398,12 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
return super.unwrap(iface);
|
||||
}
|
||||
|
||||
public boolean isLogDiffrentThread() {
|
||||
return logDiffrentThread;
|
||||
}
|
||||
|
||||
public void setLogDiffrentThread(boolean logDiffrentThread) {
|
||||
this.logDiffrentThread = logDiffrentThread;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLBooleanExpr extends SQLExprImpl implements SQLExpr, SQLLiteralExpr {
|
||||
|
||||
private boolean value;
|
||||
|
||||
public SQLBooleanExpr(){
|
||||
|
||||
}
|
||||
|
||||
public SQLBooleanExpr(boolean value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
buf.append("x");
|
||||
buf.append(value ? "TRUE" : "FALSE");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (value ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SQLBooleanExpr other = (SQLBooleanExpr) obj;
|
||||
if (value != other.value) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -228,7 +228,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
String chars = lexer.stringVal();
|
||||
concat.addParameter(new SQLCharExpr(chars));
|
||||
lexer.nextToken();
|
||||
} while (lexer.token() == Token.LITERAL_CHARS);
|
||||
} while (lexer.token() == Token.LITERAL_CHARS || lexer.token() == Token.LITERAL_ALIAS);
|
||||
expr = concat;
|
||||
}
|
||||
} else if (lexer.token() == Token.IDENTIFIER) {
|
||||
|
||||
@@ -105,6 +105,7 @@ public class MySqlLexer extends Lexer {
|
||||
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.LINE_COMMENT;
|
||||
hasComment = true;
|
||||
|
||||
if (commentHandler != null && commentHandler.handle(lastToken, stringVal)) {
|
||||
return;
|
||||
@@ -440,6 +441,7 @@ public class MySqlLexer extends Lexer {
|
||||
} else {
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
hasComment = true;
|
||||
}
|
||||
|
||||
if (commentHandler != null && commentHandler.handle(lastToken, stringVal)) {
|
||||
@@ -481,6 +483,7 @@ public class MySqlLexer extends Lexer {
|
||||
|
||||
stringVal = subString(mark, bufPos + 1);
|
||||
token = Token.LINE_COMMENT;
|
||||
hasComment = true;
|
||||
|
||||
if (commentHandler != null && commentHandler.handle(lastToken, stringVal)) {
|
||||
return;
|
||||
|
||||
@@ -161,7 +161,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
return visit((MySqlSelectQueryBlock) select);
|
||||
}
|
||||
|
||||
return false;
|
||||
return super.visit(select);
|
||||
}
|
||||
|
||||
public boolean visit(MySqlSelectQueryBlock x) {
|
||||
@@ -374,7 +374,6 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(" CHARACTER SET ");
|
||||
print(x.getCharSetName());
|
||||
}
|
||||
|
||||
if (x.getCollate() != null) {
|
||||
print(" COLLATE ");
|
||||
print(x.getCollate());
|
||||
|
||||
+18
@@ -22,6 +22,7 @@ import java.util.Properties;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLHexExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
@@ -31,6 +32,7 @@ import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
@@ -179,6 +181,22 @@ public class MySqlParameterizedOutputVisitor extends MySqlOutputVisitor implemen
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLHexExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(MySqlCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
protected void printValuesList(MySqlInsertStatement x) {
|
||||
List<ValuesClause> valuesList = x.getValuesList();
|
||||
|
||||
@@ -92,6 +92,7 @@ public class OdpsLexer extends Lexer {
|
||||
} else {
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
hasComment = true;
|
||||
}
|
||||
|
||||
if (token != Token.HINT && !isAllowComment()) {
|
||||
@@ -134,6 +135,7 @@ public class OdpsLexer extends Lexer {
|
||||
|
||||
stringVal = subString(mark + 1, bufPos);
|
||||
token = Token.LINE_COMMENT;
|
||||
hasComment = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +230,7 @@ public class OracleLexer extends Lexer {
|
||||
} else {
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
hasComment = true;
|
||||
}
|
||||
|
||||
if (token != Token.HINT && !isAllowComment()) {
|
||||
@@ -272,6 +273,7 @@ public class OracleLexer extends Lexer {
|
||||
|
||||
stringVal = subString(mark + 1, bufPos);
|
||||
token = Token.LINE_COMMENT;
|
||||
hasComment = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2181,6 +2181,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
}
|
||||
print(";");
|
||||
|
||||
decrementIndent();
|
||||
return false;
|
||||
@@ -2202,6 +2203,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
}
|
||||
print(";");
|
||||
|
||||
decrementIndent();
|
||||
return false;
|
||||
@@ -2232,6 +2234,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
println();
|
||||
}
|
||||
}
|
||||
print(";");
|
||||
decrementIndent();
|
||||
|
||||
for (ElseIf elseIf : x.getElseIfList()) {
|
||||
|
||||
@@ -100,6 +100,7 @@ public class SQLServerLexer extends Lexer {
|
||||
} else {
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
hasComment = true;
|
||||
}
|
||||
|
||||
if (token != Token.HINT && !isAllowComment()) {
|
||||
@@ -142,6 +143,7 @@ public class SQLServerLexer extends Lexer {
|
||||
|
||||
stringVal = subString(mark + 1, bufPos);
|
||||
token = Token.LINE_COMMENT;
|
||||
hasComment = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
|
||||
@@ -90,5 +91,13 @@ public class SQLServerParameterizedOutputVisitor extends SQLServerOutputVisitor
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLVariantRefExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x) || x.getName().equalsIgnoreCase("?")) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ public class Lexer {
|
||||
private int varIndex = -1;
|
||||
|
||||
protected CommentHandler commentHandler;
|
||||
|
||||
protected boolean hasComment = false;
|
||||
|
||||
public Lexer(String input){
|
||||
this(input, true);
|
||||
@@ -747,6 +749,7 @@ public class Lexer {
|
||||
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
hasComment = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -777,6 +780,7 @@ public class Lexer {
|
||||
|
||||
stringVal = subString(mark + 1, bufPos);
|
||||
token = Token.LINE_COMMENT;
|
||||
hasComment = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1045,4 +1049,8 @@ public class Lexer {
|
||||
|
||||
boolean handle(Token lastToken, String comment);
|
||||
}
|
||||
|
||||
public boolean isHasComment() {
|
||||
return hasComment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1369,29 +1369,19 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
charType.setCharSetName(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
if (lexer.stringVal().equalsIgnoreCase("COLLATE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() != Token.IDENTIFIER) {
|
||||
throw new ParserException();
|
||||
}
|
||||
charType.setCollate(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
}else if(identifierEquals("COLLATE")){
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() != Token.IDENTIFIER) {
|
||||
throw new ParserException();
|
||||
}
|
||||
|
||||
charType.setCollate(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
if (lexer.stringVal().equalsIgnoreCase("COLLATE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() != Token.IDENTIFIER) {
|
||||
throw new ParserException();
|
||||
}
|
||||
charType.setCollate(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
return charType;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLHexExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
@@ -55,13 +56,18 @@ public class ParameterizedOutputVisitorUtils {
|
||||
return sql;
|
||||
}
|
||||
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
ParameterizedVisitor visitor = createParameterizedOutputVisitor(out, dbType);
|
||||
stmt.accept(visitor);
|
||||
|
||||
if (visitor.getReplaceCount() == 0) {
|
||||
for (int i = 0; i < statementList.size(); i++) {
|
||||
if (i > 0) {
|
||||
out.append(";\n");
|
||||
}
|
||||
SQLStatement stmt = statementList.get(i);
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
|
||||
if (visitor.getReplaceCount() == 0 && !parser.getLexer().isHasComment()) {
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -190,6 +196,18 @@ public class ParameterizedOutputVisitorUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean visit(ParameterizedVisitor v, SQLVariantRefExpr x) {
|
||||
v.print('?');
|
||||
v.incrementReplaceCunt();
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean visit(ParameterizedVisitor v, SQLHexExpr x) {
|
||||
v.print('?');
|
||||
v.incrementReplaceCunt();
|
||||
return false;
|
||||
}
|
||||
|
||||
public static SQLBinaryOpExpr merge(ParameterizedVisitor v, SQLBinaryOpExpr x) {
|
||||
SQLExpr left = x.getLeft();
|
||||
SQLExpr right = x.getRight();
|
||||
@@ -198,8 +216,17 @@ public class ParameterizedOutputVisitorUtils {
|
||||
if (left instanceof SQLLiteralExpr && right instanceof SQLLiteralExpr) {
|
||||
if (x.getOperator() == SQLBinaryOperator.Equality //
|
||||
|| x.getOperator() == SQLBinaryOperator.NotEqual) {
|
||||
left.putAttribute(ATTR_PARAMS_SKIP, true);
|
||||
right.putAttribute(ATTR_PARAMS_SKIP, true);
|
||||
if((left instanceof SQLIntegerExpr) && (right instanceof SQLIntegerExpr) ) {
|
||||
if (((SQLIntegerExpr) left).getNumber().intValue() < 100) {
|
||||
left.putAttribute(ATTR_PARAMS_SKIP, true);
|
||||
}
|
||||
if (((SQLIntegerExpr) right).getNumber().intValue() < 100) {
|
||||
right.putAttribute(ATTR_PARAMS_SKIP, true);
|
||||
}
|
||||
} else {
|
||||
left.putAttribute(ATTR_PARAMS_SKIP, true);
|
||||
right.putAttribute(ATTR_PARAMS_SKIP, true);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement.TriggerEvent;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement.TriggerType;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropFunctionStatement;
|
||||
@@ -608,7 +609,9 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
decrementIndent();
|
||||
} else if (parent instanceof ValuesClause) {
|
||||
println();
|
||||
print("(");
|
||||
x.getSubQuery().accept(this);
|
||||
print(")");
|
||||
println();
|
||||
} else {
|
||||
print("(");
|
||||
@@ -1418,6 +1421,27 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCreateViewStatement x) {
|
||||
print("CREATE ");
|
||||
if(x.isOrReplace()) {
|
||||
print("OR REPLACE ");
|
||||
}
|
||||
print("VIEW ");
|
||||
x.getName().accept(this);
|
||||
|
||||
if (x.getColumns().size() > 0) {
|
||||
print(" (");
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(")");
|
||||
}
|
||||
|
||||
print(" AS ");
|
||||
|
||||
x.getSubQuery().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropIndex x) {
|
||||
|
||||
@@ -1282,6 +1282,49 @@ public class SQLEvalVisitorUtils {
|
||||
|
||||
return BigInteger.valueOf(((Number) val).longValue());
|
||||
}
|
||||
|
||||
public static Number castToNumber(String val) {
|
||||
if (val == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Byte.parseByte(val);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return Short.parseShort(val);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return Integer.parseInt(val);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return Long.parseLong(val);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return Float.parseFloat(val);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return Double.parseDouble(val);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return new BigInteger(val);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
return new BigDecimal(val);
|
||||
}
|
||||
|
||||
public static Date castToDate(Object val) {
|
||||
if (val == null) {
|
||||
@@ -1387,6 +1430,14 @@ public class SQLEvalVisitorUtils {
|
||||
if (a == null || b == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (a instanceof String) {
|
||||
a = castToNumber((String) a);
|
||||
}
|
||||
|
||||
if (b instanceof String) {
|
||||
b = castToNumber((String) b);
|
||||
}
|
||||
|
||||
if (a instanceof BigDecimal || b instanceof BigDecimal) {
|
||||
BigDecimal decimalA = castToDecimal(a);
|
||||
@@ -1664,6 +1715,14 @@ public class SQLEvalVisitorUtils {
|
||||
if (a == EVAL_VALUE_NULL || b == EVAL_VALUE_NULL) {
|
||||
return EVAL_VALUE_NULL;
|
||||
}
|
||||
|
||||
if (a instanceof String && !(b instanceof String)) {
|
||||
a = castToNumber((String) a);
|
||||
}
|
||||
|
||||
if (b instanceof String && !(a instanceof String)) {
|
||||
b = castToNumber((String) b);
|
||||
}
|
||||
|
||||
if (a instanceof BigDecimal || b instanceof BigDecimal) {
|
||||
return castToDecimal(a).add(castToDecimal(b));
|
||||
@@ -1704,7 +1763,7 @@ public class SQLEvalVisitorUtils {
|
||||
return castToByte(a) + castToByte(b);
|
||||
}
|
||||
|
||||
if (a instanceof String || b instanceof String) {
|
||||
if (a instanceof String && b instanceof String) {
|
||||
return castToString(a) + castToString(b);
|
||||
}
|
||||
|
||||
@@ -1727,6 +1786,14 @@ public class SQLEvalVisitorUtils {
|
||||
if (a instanceof Date || b instanceof Date) {
|
||||
return SQLEvalVisitor.EVAL_ERROR;
|
||||
}
|
||||
|
||||
if (a instanceof String) {
|
||||
a = castToNumber((String) a);
|
||||
}
|
||||
|
||||
if (b instanceof String) {
|
||||
b = castToNumber((String) b);
|
||||
}
|
||||
|
||||
if (a instanceof BigDecimal || b instanceof BigDecimal) {
|
||||
return castToDecimal(a).subtract(castToDecimal(b));
|
||||
@@ -1767,10 +1834,6 @@ public class SQLEvalVisitorUtils {
|
||||
return castToByte(a) - castToByte(b);
|
||||
}
|
||||
|
||||
if (a instanceof String && b instanceof String) {
|
||||
return castToLong(a) - castToLong(b);
|
||||
}
|
||||
|
||||
// return SQLEvalVisitor.EVAL_ERROR;
|
||||
throw new IllegalArgumentException(a.getClass() + " and " + b.getClass() + " not supported.");
|
||||
}
|
||||
@@ -1780,6 +1843,14 @@ public class SQLEvalVisitorUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (a instanceof String) {
|
||||
a = castToNumber((String) a);
|
||||
}
|
||||
|
||||
if (b instanceof String) {
|
||||
b = castToNumber((String) b);
|
||||
}
|
||||
|
||||
if (a instanceof BigDecimal || b instanceof BigDecimal) {
|
||||
return castToDecimal(a).multiply(castToDecimal(b));
|
||||
}
|
||||
@@ -1787,6 +1858,14 @@ public class SQLEvalVisitorUtils {
|
||||
if (a instanceof BigInteger || b instanceof BigInteger) {
|
||||
return castToBigInteger(a).multiply(castToBigInteger(b));
|
||||
}
|
||||
|
||||
if (a instanceof Double || b instanceof Double) {
|
||||
return castToDouble(a) * castToDouble(b);
|
||||
}
|
||||
|
||||
if (a instanceof Float || b instanceof Float) {
|
||||
return castToFloat(a) * castToFloat(b);
|
||||
}
|
||||
|
||||
if (a instanceof Long || b instanceof Long) {
|
||||
return castToLong(a) * castToLong(b);
|
||||
|
||||
Reference in New Issue
Block a user