mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
SQLUtils support addCondition & addSelectItem
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
public class SQLUtilsAddColumnTest extends TestCase {
|
||||
|
||||
public void test_select() throws Exception {
|
||||
Assert.assertEquals("SELECT id, name" //
|
||||
+ "\nFROM t", SQLUtils.addSelectItem("select id from t", "name", null, null));
|
||||
}
|
||||
|
||||
public void test_select_1() throws Exception {
|
||||
Assert.assertEquals("SELECT id, name AS XX" //
|
||||
+ "\nFROM t", SQLUtils.addSelectItem("select id from t", "name", "XX", null));
|
||||
}
|
||||
|
||||
public void test_select_2() throws Exception {
|
||||
Assert.assertEquals("SELECT id, name AS \"XX W\"" //
|
||||
+ "\nFROM t", SQLUtils.addSelectItem("select id from t", "name", "XX W", null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
|
||||
public class SQLUtilsAddConditionTest extends TestCase {
|
||||
public void test_select() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("select * from t", "id = 0", null));
|
||||
}
|
||||
|
||||
public void test_select_1() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("select * from t where id = 0", "name = 'aaa'", null));
|
||||
}
|
||||
|
||||
public void test_delete() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("delete from t", "id = 0", null));
|
||||
}
|
||||
|
||||
public void test_delete_1() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("delete from t where id = 0", "name = 'aaa'", null));
|
||||
}
|
||||
|
||||
|
||||
public void test_update() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("update t set f1 = ?", "id = 0", null));
|
||||
}
|
||||
|
||||
public void test_update_1() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0"
|
||||
+ "\n\tAND name = 'bb'", SQLUtils.addCondition("update t set f1 = ? where id = 0", "name = 'bb'", null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
|
||||
public class SQLUtilsAddConditionTest_mysql extends TestCase {
|
||||
public void test_select() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("select * from t", "id = 0", "mysql"));
|
||||
}
|
||||
|
||||
public void test_select_1() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("select * from t where id = 0", "name = 'aaa'", "mysql"));
|
||||
}
|
||||
|
||||
public void test_delete() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("delete from t", "id = 0", "mysql"));
|
||||
}
|
||||
|
||||
public void test_delete_1() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("delete from t where id = 0", "name = 'aaa'", "mysql"));
|
||||
}
|
||||
|
||||
|
||||
public void test_update() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("update t set f1 = ?", "id = 0", "mysql"));
|
||||
}
|
||||
|
||||
public void test_update_1() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0"
|
||||
+ "\n\tAND name = 'bb'", SQLUtils.addCondition("update t set f1 = ? where id = 0", "name = 'bb'", "mysql"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
|
||||
public class SQLUtilsAddConditionTest_oracle extends TestCase {
|
||||
public void test_select() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("select * from t", "id = 0", "oracle"));
|
||||
}
|
||||
|
||||
public void test_select_1() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("select * from t where id = 0", "name = 'aaa'", "oracle"));
|
||||
}
|
||||
|
||||
public void test_delete() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("delete from t", "id = 0", "oracle"));
|
||||
}
|
||||
|
||||
public void test_delete_1() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("delete from t where id = 0", "name = 'aaa'", "oracle"));
|
||||
}
|
||||
|
||||
|
||||
public void test_update() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("update t set f1 = ?", "id = 0", "oracle"));
|
||||
}
|
||||
|
||||
public void test_update_1() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0"
|
||||
+ "\n\tAND name = 'bb'", SQLUtils.addCondition("update t set f1 = ? where id = 0", "name = 'bb'", "oracle"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
|
||||
public class SQLUtilsAddConditionTest_pg extends TestCase {
|
||||
public void test_select() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("select * from t", "id = 0", "postgresql"));
|
||||
}
|
||||
|
||||
public void test_select_1() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("select * from t where id = 0", "name = 'aaa'", "postgresql"));
|
||||
}
|
||||
|
||||
public void test_delete() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("delete from t", "id = 0", "postgresql"));
|
||||
}
|
||||
|
||||
public void test_delete_1() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("delete from t where id = 0", "name = 'aaa'", "postgresql"));
|
||||
}
|
||||
|
||||
|
||||
public void test_update() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("update t set f1 = ?", "id = 0", "postgresql"));
|
||||
}
|
||||
|
||||
public void test_update_1() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0"
|
||||
+ "\n\tAND name = 'bb'", SQLUtils.addCondition("update t set f1 = ? where id = 0", "name = 'bb'", "postgresql"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
|
||||
public class SQLUtilsAddConditionTest_sqlserver extends TestCase {
|
||||
public void test_select() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("select * from t", "id = 0", "sqlserver"));
|
||||
}
|
||||
|
||||
public void test_select_1() throws Exception {
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("select * from t where id = 0", "name = 'aaa'", "sqlserver"));
|
||||
}
|
||||
|
||||
public void test_delete() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("delete from t", "id = 0", "sqlserver"));
|
||||
}
|
||||
|
||||
public void test_delete_1() throws Exception {
|
||||
Assert.assertEquals("DELETE FROM t" //
|
||||
+ "\nWHERE id = 0" //
|
||||
+ "\n\tAND name = 'aaa'", SQLUtils.addCondition("delete from t where id = 0", "name = 'aaa'", "sqlserver"));
|
||||
}
|
||||
|
||||
|
||||
public void test_update() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0", SQLUtils.addCondition("update t set f1 = ?", "id = 0", "sqlserver"));
|
||||
}
|
||||
|
||||
public void test_update_1() throws Exception {
|
||||
Assert.assertEquals("UPDATE t"//
|
||||
+ "\nSET f1 = ?" //
|
||||
+ "\nWHERE id = 0"
|
||||
+ "\n\tAND name = 'bb'", SQLUtils.addCondition("update t set f1 = ? where id = 0", "name = 'bb'", "sqlserver"));
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class SQLServerUpdateTest extends TestCase {
|
||||
"\n\t\tGROUP BY a.FId" +
|
||||
"\n\t\t) b" +
|
||||
"\nWHERE a.FId = b.FId" +
|
||||
"\nAND a.FId = ?";
|
||||
"\n\tAND a.FId = ?";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
Reference in New Issue
Block a user