diff options
author | James Moger <james.moger@gmail.com> | 2012-01-11 09:20:51 -0500 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2012-01-11 09:20:51 -0500 |
commit | 2e077918649d398dce0948cb3feeb61b925ee8a4 (patch) | |
tree | 2488329364248fb08e346314ba53399d9230bf64 /tests | |
parent | 28d2cf5b30ba18f20db54ed9447bc19cb0e4e1b0 (diff) | |
download | iciql-2e077918649d398dce0948cb3feeb61b925ee8a4.tar.gz iciql-2e077918649d398dce0948cb3feeb61b925ee8a4.zip |
Generate SELECT T0.* type statementsv0.7.8
* Fixed negative rollover bug in the AS counter.
* Replaced the non-threadsafe AS counter with an AtomicInteger.
* Added an optional alias parameter to Query.toSQL() and
QueryWhere.toSQL() to force SELECT T0.* select lists
* Fixed bug with Query.select(Z z) which assumed that z is always an
anonymous inner class.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/com/iciql/test/RuntimeQueryTest.java | 43 | ||||
-rw-r--r-- | tests/com/iciql/test/SamplesTest.java | 2 |
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/com/iciql/test/RuntimeQueryTest.java b/tests/com/iciql/test/RuntimeQueryTest.java index 9b306df..bb43a4f 100644 --- a/tests/com/iciql/test/RuntimeQueryTest.java +++ b/tests/com/iciql/test/RuntimeQueryTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import java.sql.ResultSet;
import java.sql.SQLException;
+import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.List;
@@ -26,10 +27,12 @@ import org.junit.Assume; import org.junit.Test;
import com.iciql.Db;
+import com.iciql.QueryWhere;
import com.iciql.test.models.EnumModels.Tree;
import com.iciql.test.models.Product;
import com.iciql.test.models.StaticQueries;
import com.iciql.util.JdbcUtils;
+import com.iciql.util.Utils;
/**
* Tests the runtime dynamic query function.
@@ -81,6 +84,46 @@ public class RuntimeQueryTest { }
@Test
+ public void testRuntimeSelectWildcards() {
+ Db db = IciqlSuite.openNewDb();
+
+ // do not test non-H2 databases because dialects will get in the way
+ // e.g. column quoting, etc
+ Assume.assumeTrue(IciqlSuite.isH2(db));
+
+ StaticQueries.StaticModel1 m1 = new StaticQueries.StaticModel1();
+ StaticQueries.StaticModel2 m2 = new StaticQueries.StaticModel2();
+ StaticQueries.StaticModel2 m3 = new StaticQueries.StaticModel2();
+
+ int t0 = Utils.AS_COUNTER.get() + 1;
+ int t1 = t0 + 1;
+
+ QueryWhere<?> where = db.from(m1).innerJoin(m2).on(m1.id).is(m2.id).where(m2.myTree).is(Tree.MAPLE);
+ String q1 = where.toSQL(false);
+ String q2 = where.toSQL(true);
+ String q3 = where.toSQL(false, m1);
+ String q4 = where.toSQL(true, m1);
+ String q5 = where.toSQL(false, m2);
+ String q6 = where.toSQL(true, m2);
+
+ // test unused alias
+ String q7 = where.toSQL(true, m3);
+
+ db.close();
+
+ assertEquals(MessageFormat.format("SELECT * FROM StaticQueryTest1 AS T{0,number,0} INNER JOIN StaticQueryTest2 AS T{1,number,0} ON T{0,number,0}.id = T{1,number,0}.id WHERE T{1,number,0}.myTree = 50", t0, t1), q1);
+ assertEquals(MessageFormat.format("SELECT DISTINCT * FROM StaticQueryTest1 AS T{0,number,0} INNER JOIN StaticQueryTest2 AS T{1,number,0} ON T{0,number,0}.id = T{1,number,0}.id WHERE T{1,number,0}.myTree = 50", t0, t1), q2);
+
+ assertEquals(MessageFormat.format("SELECT T{0,number,0}.* FROM StaticQueryTest1 AS T{0,number,0} INNER JOIN StaticQueryTest2 AS T{1,number,0} ON T{0,number,0}.id = T{1,number,0}.id WHERE T{1,number,0}.myTree = 50", t0, t1), q3);
+ assertEquals(MessageFormat.format("SELECT DISTINCT T{0,number,0}.* FROM StaticQueryTest1 AS T{0,number,0} INNER JOIN StaticQueryTest2 AS T{1,number,0} ON T{0,number,0}.id = T{1,number,0}.id WHERE T{1,number,0}.myTree = 50", t0, t1), q4);
+
+ assertEquals(MessageFormat.format("SELECT T{1,number,0}.* FROM StaticQueryTest1 AS T{0,number,0} INNER JOIN StaticQueryTest2 AS T{1,number,0} ON T{0,number,0}.id = T{1,number,0}.id WHERE T{1,number,0}.myTree = 50", t0, t1), q5);
+ assertEquals(MessageFormat.format("SELECT DISTINCT T{1,number,0}.* FROM StaticQueryTest1 AS T{0,number,0} INNER JOIN StaticQueryTest2 AS T{1,number,0} ON T{0,number,0}.id = T{1,number,0}.id WHERE T{1,number,0}.myTree = 50", t0, t1), q6);
+
+ assertEquals(MessageFormat.format("SELECT DISTINCT * FROM StaticQueryTest1 AS T{0,number,0} INNER JOIN StaticQueryTest2 AS T{1,number,0} ON T{0,number,0}.id = T{1,number,0}.id WHERE T{1,number,0}.myTree = 50", t0, t1), q7);
+ }
+
+ @Test
public void testRuntimeQuery() {
Db db = IciqlSuite.openNewDb();
db.insertAll(Product.getList());
diff --git a/tests/com/iciql/test/SamplesTest.java b/tests/com/iciql/test/SamplesTest.java index 5179d79..49a64f5 100644 --- a/tests/com/iciql/test/SamplesTest.java +++ b/tests/com/iciql/test/SamplesTest.java @@ -105,8 +105,10 @@ public class SamplesTest { Product p = new Product();
List<Product> soldOutProducts = db.from(p).where(p.unitsInStock).is(0).orderBy(p.productId).select();
+ List<Product> soldOutProducts2 = db.from(p).where(p.unitsInStock).is(0).orderBy(p.productId).select(p);
assertEquals("[Chef Anton's Gumbo Mix: 0]", soldOutProducts.toString());
+ assertEquals(soldOutProducts.toString(), soldOutProducts2.toString());
}
@Test
|