mirror of https://github.com/alibaba/druid.git
Compare commits
3 Commits
f559e2bbe8
...
8df91a8279
Author | SHA1 | Date |
---|---|---|
|
8df91a8279 | |
|
31177b91f6 | |
|
0736876199 |
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>druid</artifactId>
|
||||
|
|
|
@ -1677,10 +1677,6 @@ public class Lexer {
|
|||
scanChar();
|
||||
scanChar();
|
||||
token = Token.LTLT;
|
||||
} else if (c1 == '@') {
|
||||
scanChar();
|
||||
scanChar();
|
||||
token = Token.LT_MONKEYS_AT;
|
||||
} else if (c1 == '-' && charAt(pos + 2) == '>') {
|
||||
scanChar();
|
||||
scanChar();
|
||||
|
|
|
@ -3,16 +3,23 @@ package com.alibaba.druid.mysql;
|
|||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
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.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BinaryOperator;
|
||||
|
||||
/**
|
||||
* Created by szf on 2017/11/16.
|
||||
|
@ -150,4 +157,54 @@ public class MysqlVarantRefTest {
|
|||
Assert.assertTrue(resultExpr5.isSession());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7() {
|
||||
// in this case, < @sid is recognized as < operator and user-defined variables@sid
|
||||
String sql = "set @sid=1;select * from aaa where id < @sid; ";
|
||||
SQLStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
|
||||
SQLSetStatement result0 = (SQLSetStatement) stmtList.get(0);
|
||||
SQLVariantRefExpr resultExpr0 = (SQLVariantRefExpr) result0.getItems().get(0).getTarget();
|
||||
Assert.assertEquals("@sid", resultExpr0.getName());
|
||||
|
||||
AtomicReference<SQLVariantRefExpr> resultExpr1Ref = new AtomicReference<>();
|
||||
AtomicInteger variableCnt = new AtomicInteger(0);
|
||||
AtomicInteger arrayContainerByOperatorCnt = new AtomicInteger(0);
|
||||
MySqlASTVisitor visitor = new MySqlASTVisitorAdapter() {
|
||||
@Override
|
||||
public boolean visit(SQLVariantRefExpr x) {
|
||||
resultExpr1Ref.set(x);
|
||||
variableCnt.addAndGet(1);
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
if(SQLBinaryOperator.Array_ContainedBy.equals(x.getOperator())) {
|
||||
arrayContainerByOperatorCnt.addAndGet(1);
|
||||
}
|
||||
return super.visit(x);
|
||||
}
|
||||
};
|
||||
stmtList.get(1).accept(visitor);
|
||||
|
||||
|
||||
Assert.assertEquals(1, variableCnt.get());
|
||||
Assert.assertEquals(0, arrayContainerByOperatorCnt.get());
|
||||
Assert.assertEquals("@sid", resultExpr1Ref.get().getName());
|
||||
|
||||
// in this case, <@ is recognized as <@, instead of < user-defined variables@sid
|
||||
String sql2 = "select * from aaa where id <@ sid; ";
|
||||
SQLStatementParser parser2 = new MySqlStatementParser(sql2);
|
||||
|
||||
List<SQLStatement> stmtList2 = parser2.parseStatementList();
|
||||
variableCnt.set(0);
|
||||
arrayContainerByOperatorCnt.set(0);
|
||||
resultExpr1Ref.set(null);
|
||||
stmtList2.get(0).accept(visitor);
|
||||
Assert.assertEquals(0, variableCnt.get());
|
||||
Assert.assertEquals(1, arrayContainerByOperatorCnt.get());
|
||||
Assert.assertNull(resultExpr1Ref.get());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Spring and Spring Boot dependencies -->
|
||||
<dependency>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
|
14
pom.xml
14
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<name>${project.artifactId}</name>
|
||||
<description>A JDBC datasource implementation.</description>
|
||||
<packaging>pom</packaging>
|
||||
|
@ -81,12 +81,12 @@
|
|||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
<id>central</id>
|
||||
<url>https://central.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<id>central</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
|
@ -470,8 +470,8 @@
|
|||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
||||
<serverId>central</serverId>
|
||||
<nexusUrl>https://central.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
<!--
|
||||
If you are deploying to Maven Central,
|
||||
|
|
Loading…
Reference in New Issue