[CalendarServer-changes] [9645] CalendarServer/branches/users/glyph/q
source_changes at macosforge.org
source_changes at macosforge.org
Sat Aug 11 01:55:18 PDT 2012
Revision: 9645
http://trac.macosforge.org/projects/calendarserver/changeset/9645
Author: glyph at apple.com
Date: 2012-08-11 01:55:18 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
Don't test ordering just yet; make the query test pass.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/q/
Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py 2012-08-11 08:55:17 UTC (rev 9644)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py 2012-08-11 08:55:18 UTC (rev 9645)
@@ -92,17 +92,7 @@
@classmethod
@inlineCallbacks
def load(cls, txn, *primaryKey):
- tbl = cls.__tbl__
- allColumns = list(tbl)
- slct = Select(allColumns, From=tbl,
- Where=cls._primaryKeyComparison(primaryKey))
- rows = yield slct.on(txn)
- row = rows[0]
- self = cls()
- for (column, value) in zip(allColumns, row):
- name = cls.__colmap__[column]
- setattr(self, name, value)
- self.__txn__ = txn
+ self = (yield cls.query(txn, cls._primaryKeyComparison(primaryKey)))[0]
returnValue(self)
@@ -160,8 +150,23 @@
@classmethod
@inlineCallbacks
def query(cls, txn, expr, order=None):
- yield None
- returnValue([])
+ """
+ Query the table that corresponds to C{cls}, and return instances of
+ C{cls} corresponding to the rows that are returned from that table.
+ """
+ tbl = cls.__tbl__
+ allColumns = list(tbl)
+ slct = Select(allColumns, From=tbl, Where=expr)
+ rows = yield slct.on(txn)
+ selves = []
+ for row in rows:
+ self = cls()
+ for (column, value) in zip(allColumns, row):
+ name = cls.__colmap__[column]
+ setattr(self, name, value)
+ self.__txn__ = txn
+ selves.append(self)
+ returnValue(selves)
Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py 2012-08-11 08:55:17 UTC (rev 9644)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py 2012-08-11 08:55:18 UTC (rev 9645)
@@ -168,10 +168,9 @@
(356, u"three"), (456, u"four")]:
yield txn.execSQL("insert into ALPHA values (:1, :2)",
[beta, gamma])
- records = yield TestRecord.query(txn,
- TestRecord.gamma == u"three",
- TestRecord.beta)
+ records = yield TestRecord.query(txn, TestRecord.gamma == u"three")
self.assertEqual(len(records), 2)
+ records.sort(key=lambda x: x.beta)
self.assertEqual(records[0].beta, 345)
self.assertEqual(records[1].beta, 356)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/b2966c0f/attachment.html>
More information about the calendarserver-changes
mailing list