mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase & remove unused code
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
public class SQLCommentStatementTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "COMMENT on table t1 IS 'xxx'";
|
||||
|
||||
SQLStatementParser parser = new SQLStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.outputSqlServer(stmt);
|
||||
|
||||
Assert.assertEquals("COMMENT ON TABLE t1 IS 'xxx'", text);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodAbsTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
public void test_abs_int() throws Exception {
|
||||
Assert.assertEquals(12, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "abs(-12)"));
|
||||
Assert.assertEquals(12, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "abs(12)"));
|
||||
}
|
||||
|
||||
public void test_abs_long() throws Exception {
|
||||
Assert.assertEquals(12L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "abs(?)", 12L));
|
||||
Assert.assertEquals(12L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "abs(?)", -12L));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodCosTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.cos(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "cos(1)"));
|
||||
Assert.assertEquals(Math.cos(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "cos(1.001)"));
|
||||
Assert.assertEquals(Math.cos(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "cos(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodLog10Test extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.log10(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log10(1)"));
|
||||
Assert.assertEquals(Math.log10(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log10(1.001)"));
|
||||
Assert.assertEquals(Math.log10(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log10(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodLogTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.log(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log(1)"));
|
||||
Assert.assertEquals(Math.log(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log(1.001)"));
|
||||
Assert.assertEquals(Math.log(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodPowerTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.pow(1, 2), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "power(1, 2)"));
|
||||
Assert.assertEquals(Math.pow(3, 4), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "power(3, 4)"));
|
||||
Assert.assertEquals(Math.pow(4, 5), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "pow(4, 5)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodRandom extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertNotNull(SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "rand()"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodSinTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.sin(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sin(1)"));
|
||||
Assert.assertEquals(Math.sin(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sin(1.001)"));
|
||||
Assert.assertEquals(Math.sin(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sin(0)"));
|
||||
Assert.assertEquals(Math.sin(2), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sin(2)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodSqrtTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.sqrt(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sqrt(1)"));
|
||||
Assert.assertEquals(Math.sqrt(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sqrt(1.001)"));
|
||||
Assert.assertEquals(Math.sqrt(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sqrt(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodTanTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.tan(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "tan(1)"));
|
||||
Assert.assertEquals(Math.tan(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "tan(1.001)"));
|
||||
Assert.assertEquals(Math.tan(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "tan(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_add extends TestCase {
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(3, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte_1() throws Exception {
|
||||
Assert.assertEquals(3, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (byte) 1, "2"));
|
||||
}
|
||||
|
||||
public void test_byte_2() throws Exception {
|
||||
Assert.assertEquals(null, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (byte) 1, null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_add_long extends TestCase {
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(3L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte_1() throws Exception {
|
||||
Assert.assertEquals(3L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (long) 1, "2"));
|
||||
}
|
||||
|
||||
public void test_byte_2() throws Exception {
|
||||
Assert.assertEquals(null, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (long) 1, null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_add_short extends TestCase {
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(3, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte_1() throws Exception {
|
||||
Assert.assertEquals(3, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (short) 1, "2"));
|
||||
}
|
||||
|
||||
public void test_byte_2() throws Exception {
|
||||
Assert.assertEquals(null, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (short) 1, null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_div extends TestCase {
|
||||
public void test_long() throws Exception {
|
||||
Assert.assertEquals(0L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_int() throws Exception {
|
||||
Assert.assertEquals(0, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (int) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_short() throws Exception {
|
||||
Assert.assertEquals(0, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(0, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigInteger() throws Exception {
|
||||
Assert.assertEquals(BigInteger.ZERO, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", BigInteger.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigDecimal() throws Exception {
|
||||
Assert.assertEquals(new BigDecimal("0.5"), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", BigDecimal.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_float() throws Exception {
|
||||
Assert.assertEquals(0.5F, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (float) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_double() throws Exception {
|
||||
Assert.assertEquals(0.5D, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (double) 1, (byte) 2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_gt extends TestCase {
|
||||
public void test_long() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? > ?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_int() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? > ?", (int) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_short() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? > ?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? > ?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigInteger() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", BigInteger.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigDecimal() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", BigDecimal.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_float() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", (float) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_double() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", (double) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_String() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", "1", "2"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_lt extends TestCase {
|
||||
public void test_long() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? < ?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_int() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? < ?", (int) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_short() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? < ?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? < ?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigInteger() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", BigInteger.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigDecimal() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", BigDecimal.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_float() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", (float) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_double() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", (double) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_String() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", "1", "2"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_lteq extends TestCase {
|
||||
public void test_long() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? <= ?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_int() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? <= ?", (int) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_short() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? <= ?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? <= ?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigInteger() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", BigInteger.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigDecimal() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", BigDecimal.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_float() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", (float) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_double() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", (double) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_String() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", "1", "2"));
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -31,13 +31,13 @@ public class MySqlParameterizedOutputVisitorTest extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
validate("SELECT * FROM T WHERE ID IN (?, ?, ?)", "SELECT *\nFROM T\nWHERE ID IN (?)");
|
||||
validate("SELECT * FROM T WHERE ID = 5", "SELECT *\nFROM T\nWHERE ID = ?");
|
||||
validate("SELECT * FROM T WHERE 1 = 0 AND ID = 5", "SELECT *\nFROM T\nWHERE 1 = 0\nAND ID = ?");
|
||||
validate("SELECT * FROM T WHERE 1 = 0 AND ID = 5", "SELECT *\nFROM T\nWHERE 1 = 0\n\tAND ID = ?");
|
||||
validate("SELECT * FROM T WHERE ID = ? OR ID = ?", "SELECT *\nFROM T\nWHERE ID = ?");
|
||||
validate("SELECT * FROM T WHERE A.ID = ? OR A.ID = ?", "SELECT *\nFROM T\nWHERE A.ID = ?");
|
||||
validate("SELECT * FROM T WHERE 1 = 0 OR a.id = ? OR a.id = ? OR a.id = ? OR a.id = ?",
|
||||
"SELECT *\nFROM T\nWHERE 1 = 0\nOR a.id = ?");
|
||||
"SELECT *\nFROM T\nWHERE 1 = 0\n\tOR a.id = ?");
|
||||
validateOracle("SELECT * FROM T WHERE 1 = 0 OR a.id = ? OR a.id = ? OR a.id = ? OR a.id = ?",
|
||||
"SELECT *\nFROM T\nWHERE 1 = 0\nOR a.id = ?");
|
||||
"SELECT *\nFROM T\nWHERE 1 = 0\n\tOR a.id = ?");
|
||||
validateOracle("SELECT * FROM T WHERE A.ID = ? OR A.ID = ?", "SELECT *\nFROM T\nWHERE A.ID = ?");
|
||||
validate("INSERT INTO T (F1, F2) VALUES(?, ?), (?, ?), (?, ?)", "INSERT INTO T (F1, F2) VALUES (?, ?)");
|
||||
validate("update net_device d, sys_user u set d.resp_user_id=u.id where d.resp_user_login_name=u.username and d.id in (42354)", //
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
|
||||
public class MySqlUpdateTest_2 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "UPDATE `z_code` SET (f1, f2) = (1, 2)";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
Assert.assertEquals(2, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("z_code")));
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("z_code", "f1")));
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("z_code", "f2")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.bvt.sql.oracle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
|
||||
public class OracleSelectTest43 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"SELECT * FROM table(t_department) " + //
|
||||
"WHERE name IN ('0000','4444') " + //
|
||||
"ORDER BY name ASC"; //
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
|
||||
Assert.assertEquals(1, visitor.getColumns().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
|
||||
// Assert.assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ package com.alibaba.druid.bvt.sql.oracle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alibaba.druid.bvt.sql.postgresql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGExportParameterVisitor;
|
||||
|
||||
|
||||
public class PGExportParameterVisitorTest extends TestCase {
|
||||
public void test_pg() throws Exception {
|
||||
String sql = "select fname, count(*) from t where fid = 1 group by fname order by 1";
|
||||
|
||||
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
PGExportParameterVisitor visitor = new PGExportParameterVisitor(parameters);
|
||||
stmt.accept(visitor);
|
||||
|
||||
Assert.assertEquals(1, parameters.size());
|
||||
Assert.assertEquals(1, parameters.get(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alibaba.druid.bvt.sql.postgresql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGExportParameterVisitor;
|
||||
|
||||
|
||||
public class PGExportParameterVisitorTest1 extends TestCase {
|
||||
public void test_pg() throws Exception {
|
||||
String sql = "select fname, count(*) from t where fid = 1 group by fname order by 1";
|
||||
|
||||
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
PGExportParameterVisitor visitor = new PGExportParameterVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
List<Object> parameters = visitor.getParameters();
|
||||
|
||||
Assert.assertEquals(1, parameters.size());
|
||||
Assert.assertEquals(1, parameters.get(0));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.MSSQLServerExportParameterVisitor;
|
||||
|
||||
public class MSSQLServerExportParameterVisitorTest extends TestCase {
|
||||
|
||||
public void test_sqlserver() throws Exception {
|
||||
String sql = "select fname, count(*) from t where fid = 1 group by fname order by 1";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
MSSQLServerExportParameterVisitor visitor = new MSSQLServerExportParameterVisitor(parameters);
|
||||
stmt.accept(visitor);
|
||||
|
||||
Assert.assertEquals(1, parameters.size());
|
||||
Assert.assertEquals(1, parameters.get(0));
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.bvt.sql.sqlserver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerParameterizedOutputVisitor;
|
||||
|
||||
public class SQLServerParameterizedOutputVisitorTest extends TestCase {
|
||||
|
||||
public void test_simple() throws Exception {
|
||||
String sql = "select GEN_VAL " + //
|
||||
"from ID_GENERATOR with (updlock, rowlock) " + //
|
||||
"where GEN_NAME = 'T_USERS' AND FID = 3 AND FSTATE IN (1, 2, 3)"; //
|
||||
|
||||
String expect = "SELECT GEN_VAL" + //
|
||||
"\nFROM ID_GENERATOR WITH (updlock, rowlock)" + //
|
||||
"\nWHERE GEN_NAME = ?" +
|
||||
"\n\tAND FID = ?" +
|
||||
"\n\tAND FSTATE IN (?)";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
|
||||
String text = outputSqlServer(stmtList);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
}
|
||||
|
||||
public static String outputSqlServer(List<SQLStatement> stmtList) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
SQLServerOutputVisitor visitor = new SQLServerParameterizedOutputVisitor(out);
|
||||
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
Reference in New Issue
Block a user