You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2007/03/24 17:00:58 UTC
svn commit: r522044 - in /db/torque:
runtime/trunk/src/java/org/apache/torque/adapter/
runtime/trunk/src/java/org/apache/torque/util/ site/trunk/xdocs/
test/trunk/test-project/src/java/org/apache/torque/
Author: tfischer
Date: Sat Mar 24 09:00:57 2007
New Revision: 522044
URL: http://svn.apache.org/viewvc?view=rev&rev=522044
Log:
- Fixed handling of select statements in mysql and postgresql if offset is set but limit is not set in a query.
- replaced tabs by spaces in DataTest.java
Fixes TORQUE-87
Modified:
db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBMM.java
db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBPostgres.java
db/torque/runtime/trunk/src/java/org/apache/torque/util/Query.java
db/torque/site/trunk/xdocs/changes.xml
db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
Modified: db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBMM.java
URL: http://svn.apache.org/viewvc/db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBMM.java?view=diff&rev=522044&r1=522043&r2=522044
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBMM.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBMM.java Sat Mar 24 09:00:57 2007
@@ -142,23 +142,27 @@
*/
public void generateLimits(Query query, int offset, int limit)
{
- StringBuffer limitStringBuffer = new StringBuffer();
-
if (offset > 0)
{
- limitStringBuffer.append(offset)
- .append(", ")
- .append(limit);
+ if (limit >=0 )
+ {
+ query.setLimit(Integer.toString(limit));
+ }
+ else
+ {
+ // Limit must always be set in mysql if offset is set
+ query.setLimit("18446744073709551615");
+ }
+ query.setOffset(Integer.toString(offset));
}
else
{
if (limit >= 0)
{
- limitStringBuffer.append(limit);
+ query.setLimit(Integer.toString(limit));
}
}
- query.setLimit(limitStringBuffer.toString());
query.setPreLimit(null);
query.setPostLimit(null);
}
Modified: db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBPostgres.java
URL: http://svn.apache.org/viewvc/db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBPostgres.java?view=diff&rev=522044&r1=522043&r2=522044
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBPostgres.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/adapter/DBPostgres.java Sat Mar 24 09:00:57 2007
@@ -159,23 +159,15 @@
*/
public void generateLimits(Query query, int offset, int limit)
{
- StringBuffer limitStringBuffer = new StringBuffer();
-
if (offset > 0)
{
- limitStringBuffer.append(limit)
- .append(" offset ")
- .append(offset);
+ query.setOffset(Integer.toString(offset));
}
- else
+ if (limit >= 0)
{
- if (limit >= 0)
- {
- limitStringBuffer.append(limit);
- }
+ query.setLimit(Integer.toString(limit));
}
- query.setLimit(limitStringBuffer.toString());
query.setPreLimit(null);
query.setPostLimit(null);
}
Modified: db/torque/runtime/trunk/src/java/org/apache/torque/util/Query.java
URL: http://svn.apache.org/viewvc/db/torque/runtime/trunk/src/java/org/apache/torque/util/Query.java?view=diff&rev=522044&r1=522043&r2=522044
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/util/Query.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/util/Query.java Sat Mar 24 09:00:57 2007
@@ -46,6 +46,7 @@
private static final String GROUP_BY = " GROUP BY ";
private static final String HAVING = " HAVING ";
private static final String LIMIT = " LIMIT ";
+ private static final String OFFSET = " OFFSET ";
private static final String ROWCOUNT = " SET ROWCOUNT ";
private UniqueList selectModifiers = new UniqueList();
@@ -58,6 +59,7 @@
private String limit;
private String preLimit;
private String postLimit;
+ private String offset;
private String rowcount;
/**
@@ -181,7 +183,7 @@
/**
* Set the limit number. This is used to limit the number of rows
- * returned by a query, and the row where the resultset starts.
+ * returned by a query.
*
* @param limit A String.
*/
@@ -213,6 +215,17 @@
}
/**
+ * Set the offset number. This is used to set the row where the
+ * resultset starts.
+ *
+ * @param offset A String.
+ */
+ public void setOffset(String offset)
+ {
+ this.offset = offset;
+ }
+
+ /**
* Set the rowcount number. This is used to limit the number of
* rows returned by Sybase and MS SQL/Server.
*
@@ -268,6 +281,17 @@
}
/**
+ * Get the offset number. This is used to set the row where the
+ * resultset starts.
+ *
+ * @return A String with the offset, or null if no offset is set.
+ */
+ public String getOffset()
+ {
+ return offset;
+ }
+
+ /**
* True if this query has a limit clause registered.
*
* @return true if a limit clause exists.
@@ -355,6 +379,11 @@
{
stmt.append(LIMIT)
.append(limit);
+ }
+ if (offset != null)
+ {
+ stmt.append(OFFSET)
+ .append(offset);
}
if (rowcount != null)
{
Modified: db/torque/site/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/db/torque/site/trunk/xdocs/changes.xml?view=diff&rev=522044&r1=522043&r2=522044
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Sat Mar 24 09:00:57 2007
@@ -30,7 +30,11 @@
</properties>
<body>
- <release version="3.3" date="in SVN">
+ <release version="3.3-RC3" date="in SVN">
+ <action type="fix" dev="tfischer" issue="TORQUE-87">
+ Fixed handling of select statements in mysql and postgresql
+ if offset is set but limit is not set in a query.
+ </action>
</release>
<release version="3.3-RC2" date="in SVN">
<action type="fix" dev="tv" issue="TORQUE-76" due-to="Ronny Völker">
Modified: db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java?view=diff&rev=522044&r1=522043&r2=522044
==============================================================================
--- db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java (original)
+++ db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java Sat Mar 24 09:00:57 2007
@@ -120,15 +120,15 @@
Connection connection = null;
try
{
- connection = Torque.getConnection();
+ connection = Torque.getConnection();
connection.close();
connection = null;
}
finally
{
- if (connection != null)
+ if (connection != null)
{
- connection.close();
+ connection.close();
}
}
}
@@ -139,6 +139,9 @@
*/
public void testInsertData() throws Exception
{
+ // remove old authors and books
+ cleanBookstore();
+
// insert books and authors
for (int i = 1; i <= 10; i++)
{
@@ -231,20 +234,27 @@
crit.setLimit(0);
try
{
- books = BookPeer.doSelect(crit);
+ books = BookPeer.doSelect(crit);
assertTrue("List should have 0 books, not " + books.size(),
- books.size() == 0);
+ books.size() == 0);
}
catch (TorqueException e)
{
- if (Torque.getDB(Torque.getDefaultDB()).supportsNativeLimit())
+ if (Torque.getDB(Torque.getDefaultDB()).supportsNativeLimit())
{
- throw e;
+ throw e;
}
log.error("testLimitOffset(): "
+ "A limit of 0 is not supported for Databases "
+ "without native limit support");
}
+
+ // check that Offset also works without limit
+ crit = new Criteria();
+ crit.setOffset(5);
+ books = MyBookPeer.doSelect(crit);
+ assertTrue("List should have 95 books, not " + books.size(),
+ books.size() == 95);
// Check that limiting also works if a table with an equal column name
// is joined. This is problematic for oracle, see TORQUE-10.
@@ -396,12 +406,12 @@
public void testBitType() throws Exception
{
if (Torque.getDB(Torque.getDefaultDB()) instanceof DBOracle
- || Torque.getDB(Torque.getDefaultDB()) instanceof DBDerby
+ || Torque.getDB(Torque.getDefaultDB()) instanceof DBDerby
|| Torque.getDB(Torque.getDefaultDB()) instanceof DBInterbase
|| Torque.getDB(Torque.getDefaultDB()) instanceof DBFirebird)
{
log.error("testBitType(): "
- + "BIT is known not to work with "
+ + "BIT is known not to work with "
+ "Oracle, Derby, Firebird and Interbase");
// failing is "expected", so exit without error
return;
@@ -1095,7 +1105,7 @@
criteria.setIgnoreCase(true);
List result = AuthorPeer.doSelect(criteria);
assertTrue("Size of result is not 1, but " + result.size(),
- result.size() == 1);
+ result.size() == 1);
// LIKE treatment might be different (e.g. postgres), so check extra
criteria = new Criteria();
@@ -1171,7 +1181,7 @@
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
result = AuthorPeer.doSelect(criteria);
assertTrue("Size of result is not 2, but " + result.size(),
- result.size() == 2);
+ result.size() == 2);
author = (Author) result.get(0);
assertEquals("First", author.getName(), "a");
@@ -1187,7 +1197,7 @@
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
result = AuthorPeer.doSelect(criteria);
assertTrue("Size of result is not 2, but " + result.size(),
- result.size() == 2);
+ result.size() == 2);
author = (Author) result.get(0);
assertEquals("First", author.getName(), "A");
}
@@ -1321,7 +1331,7 @@
// clean LargePk table
Criteria criteria = new Criteria();
criteria.add(
- LargePkPeer.LARGE_PK_ID,
+ LargePkPeer.LARGE_PK_ID,
(Long) null,
Criteria.NOT_EQUAL);
LargePkPeer.doDelete(criteria);
@@ -1335,12 +1345,12 @@
List largePkList = LargePkPeer.doSelect(new Criteria());
LargePk readLargePk = (LargePk) largePkList.get(0);
assertTrue("the inserted Id, " + largePk.getLargePkId()
- + " , and the read id, " + readLargePk.getLargePkId()
- + " , should be equal",
- readLargePk.getLargePkId() == largePk.getLargePkId());
+ + " , and the read id, " + readLargePk.getLargePkId()
+ + " , should be equal",
+ readLargePk.getLargePkId() == largePk.getLargePkId());
assertTrue("the inserted Id, " + largePk.getLargePkId()
- + " , should be equal to " + longId,
- longId == largePk.getLargePkId());
+ + " , should be equal to " + longId,
+ longId == largePk.getLargePkId());
}
/**
@@ -1458,7 +1468,7 @@
String charTemplate = "1234567890abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < length; ++i)
{
- bytes[i] = new Integer(i % 256).byteValue();
+ bytes[i] = new Integer(i % 256).byteValue();
chars.append(charTemplate.charAt(i % charTemplate.length()));
}
blobTest.setBlobValue(bytes);
@@ -1589,14 +1599,14 @@
bookEqual.setBookId(1000);
assertFalse("Author and Book should not be equal",
- author.equals(book));
+ author.equals(book));
assertTrue("Book compared with itself should be equal",
- book.equals(book));
+ book.equals(book));
assertTrue("Book compared with book with same id should be equal",
- book.equals(bookEqual));
+ book.equals(bookEqual));
assertFalse("Book compared with book with different id "
- + "should not be equal",
- book.equals(bookNotEqual));
+ + "should not be equal",
+ book.equals(bookNotEqual));
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org