MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
col.setType(ColumnType.INTEGER);
};
+
+ public void testQueryWithParenthesis() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc,
+ "select foo from sch.tbl where (foo= 1) and (foo=2)");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.foo = '1' AND tbl.foo = '2'",
+ q.toSql());
+ }
public void testQueryWithParenthesisAnd() throws Exception {
Query q = MetaModelHelper.parseQuery(dc, "select foo from sch.tbl where (foo= 1) and (foo=2)");
final Integer firstRow = query.getFirstRow();
final Integer maxRows = query.getMaxRows();
- if (maxRows == null && firstRow == null) {
+ if (maxRows == null && (firstRow == null || firstRow.intValue() == 1)) {
return super.rewriteQuery(query);
}
- if (firstRow == null || firstRow.intValue() == 1) {
+ if ((firstRow == null || firstRow.intValue() == 1) && maxRows != null && maxRows > 0) {
// We prefer to use the "FETCH FIRST [n] ROWS ONLY" approach, if
// firstRow is not specified.
return super.rewriteQuery(query) + " FETCH FIRST " + maxRows + " ROWS ONLY";
assertEquals("SELECT sch.foo.bar FROM sch.foo FETCH FIRST 200 ROWS ONLY", str);
}
+ public void testRewriteFirstRowIsOneAndMaxRowsIsNull() throws Exception {
+ Query q = new Query().from(table).select(col).setFirstRow(1);
+ String str = new DB2QueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT sch.foo.bar FROM sch.foo", str);
+ }
+
public void testRewriteFirstRow() throws Exception {
Query q = new Query().from(table).select(col).setFirstRow(401);
String str = new DB2QueryRewriter(null).rewriteQuery(q);