[CalendarServer-changes] [6883] CalendarServer/trunk/twext/enterprise/dal
source_changes at macosforge.org
source_changes at macosforge.org
Fri Feb 4 14:10:25 PST 2011
Revision: 6883
http://trac.macosforge.org/projects/calendarserver/changeset/6883
Author: sagen at apple.com
Date: 2011-02-04 14:10:25 -0800 (Fri, 04 Feb 2011)
Log Message:
-----------
A Select object with a 'Limit' keyword parameter will generate a SQL statement with a 'limit' clause.
Modified Paths:
--------------
CalendarServer/trunk/twext/enterprise/dal/syntax.py
CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
Modified: CalendarServer/trunk/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/syntax.py 2011-02-04 21:22:57 UTC (rev 6882)
+++ CalendarServer/trunk/twext/enterprise/dal/syntax.py 2011-02-04 22:10:25 UTC (rev 6883)
@@ -378,11 +378,12 @@
"""
def __init__(self, columns=None, Where=None, From=None, OrderBy=None,
- GroupBy=None):
+ GroupBy=None, Limit=None):
self.From = From
self.Where = Where
self.OrderBy = OrderBy
self.GroupBy = GroupBy
+ self.Limit = Limit
if columns is None:
columns = ALL_COLUMNS
else:
@@ -415,6 +416,10 @@
if expr is not None:
stmt.text += quote(" " + bywhat + " by ")
stmt.append(expr.subSQL(placeholder, quote, allTables))
+ if self.Limit is not None:
+ stmt.text += quote(" limit ")
+ stmt.text += placeholder
+ stmt.parameters.append(self.Limit)
return stmt
Modified: CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2011-02-04 21:22:57 UTC (rev 6882)
+++ CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2011-02-04 22:10:25 UTC (rev 6883)
@@ -415,3 +415,17 @@
self.assertEquals(Lock.exclusive(self.schema.FOO).toSQL(),
SQLFragment("lock table FOO in exclusive mode"))
+
+ def test_limit(self):
+ """
+ A L{Select} object with a 'Limit' keyword parameter will generate
+ a SQL statement with a 'limit' clause.
+ """
+ self.assertEquals(
+ Select([self.schema.FOO.BAR],
+ From=self.schema.FOO,
+ Limit=123).toSQL(),
+ SQLFragment(
+ "select BAR from FOO limit ?", [123])
+ )
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110204/08dd67cf/attachment-0001.html>
More information about the calendarserver-changes
mailing list