[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/RDB - IResultSet.py:1.5 ResultSet.py:1.4 Row.py:1.4 Util.py:1.6

Albertas Agejevas alga@codeworks.lt
Mon, 2 Dec 2002 15:03:52 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/RDB
In directory cvs.zope.org:/tmp/cvs-serv5490/lib/python/Zope/App/RDB

Modified Files:
	IResultSet.py ResultSet.py Row.py Util.py 
Log Message:
Added stats reporting to the RAMCache.
Had to make Zope.App.RDB.ResultSet pickleable on the way.
Renamed ResultSet.names to ResultSet.columns.
Updated SQLScript to pass the location to the cache, not self.


=== Zope3/lib/python/Zope/App/RDB/IResultSet.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/RDB/IResultSet.py:1.4	Wed Jul 10 19:37:26 2002
+++ Zope3/lib/python/Zope/App/RDB/IResultSet.py	Mon Dec  2 15:03:49 2002
@@ -21,8 +21,8 @@
 class IResultSet(Interface):
     """Holds results, and allows iteration."""
 
-    names = Attribute("""A list of the column names of the returned result
-                      set.""")
+    columns = Attribute("""A list of the column names of the returned result
+                           set.""")
 
     def __getitem__(index):
         """Return a brain row for index."""


=== Zope3/lib/python/Zope/App/RDB/ResultSet.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/RDB/ResultSet.py:1.3	Wed Jul 10 19:37:26 2002
+++ Zope3/lib/python/Zope/App/RDB/ResultSet.py	Mon Dec  2 15:03:49 2002
@@ -2,31 +2,65 @@
 #
 # Copyright (c) 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-# 
+#
 ##############################################################################
 """
 $Id$
 """
-from Zope.App.RDB.IResultSet import IResultSet
- 
-class ResultSet(list):    
-    """Database Result Set. 
+from IResultSet import IResultSet
+from Row import RowClassFactory
+
+class ResultSet(list):
+    """Database Result Set.
 
     Currently we don't do lazy instantation of rows.
     """
 
     __implements__ = IResultSet
-    __slots__ = ('names', 'row_klass')
-    
-    def __init__(self, names, data, row_klass):
-        self.names = tuple(names)
-        self.row_klass = row_klass
-        super(ResultSet, self).__init__(map(row_klass, data))
-    
+    __slots__ = ('columns',)
+
+    def __init__(self, columns, rows):
+        self.columns = tuple(columns)
+        row_class = RowClassFactory(columns)
+        super(ResultSet, self).__init__(map(row_class, rows))
+
+    def __setstate__(self, data):
+        self.columns, rows = data
+        row_class = RowClassFactory(self.columns)
+        self.extend(map(row_class, rows))
+
+    __safe_for_unpickling__ = True
+
+    def __reduce__(self):
+        cols = self.columns
+        return (ResultSet, None,
+                (self.columns,
+                 [[getattr(row, col) for col in cols]
+                  for row in self]
+                ))
+
+    def __basicnew__():
+        return ResultSet((), ())
+    __basicnew__ = staticmethod(__basicnew__)
+
+    def __cmp__(self, other):
+        if not isinstance(other, ResultSet):
+            return super(ResultSet, self).__cmp__(other)
+        c = cmp(self.columns, other.columns)
+        if c:
+            return c
+        for row, other_row in zip(self, other):
+            c = cmp(row, other_row)
+            if c:
+                return c
+        return cmp(len(self), len(other))
+
+
+


=== Zope3/lib/python/Zope/App/RDB/Row.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/RDB/Row.py:1.3	Wed Jul 10 19:37:26 2002
+++ Zope3/lib/python/Zope/App/RDB/Row.py	Mon Dec  2 15:03:49 2002
@@ -2,14 +2,14 @@
 #
 # Copyright (c) 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-# 
+#
 ##############################################################################
 """
 $Id$
@@ -18,23 +18,32 @@
 
 class Row(object):
     """Represents a row in a ResultSet"""
-    
+
     def __init__(self, data):
         for k, v in zip(self.__slots__, data):
             setattr(self, k, v)
 
     def __str__(self):
-        return "row class %s"%str(self.__slots__)
+        return "row class %s" % str(self.__slots__)
+
+    def __cmp__(self, other):
+        if not isinstance(other, Row):
+            return super(Row, self).__cmp__(other)
+        c = cmp(self.__slots__, other.__slots__)
+        if c:
+            return c
+        for column in self.__slots__:
+            c = cmp(getattr(self, column), getattr(other, column))
+            if c:
+                return c
+        return 0
 
-            
 def RowClassFactory(columns):
     """Creates a Row object"""
     klass_namespace = {}
-    
+
     klass_namespace['__Security_checker__'] = Checker.NamesChecker(columns)
     klass_namespace['__slots__'] = tuple(columns)
 
-    return type('row class', (Row,), klass_namespace)
-
-
+    return type('GeneratedRowClass', (Row,), klass_namespace)
 


=== Zope3/lib/python/Zope/App/RDB/Util.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/RDB/Util.py:1.5	Thu Aug  8 13:07:03 2002
+++ Zope3/lib/python/Zope/App/RDB/Util.py	Mon Dec  2 15:03:49 2002
@@ -2,14 +2,14 @@
 #
 # Copyright (c) 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-# 
+#
 ##############################################################################
 """
 $Id$
@@ -20,7 +20,7 @@
 
 def queryForResults(conn, query):
     """Convenience function to quickly execute a query."""
-    
+
     # XXX need to do typing
     cursor = conn.cursor()
 
@@ -37,9 +37,7 @@
         columns = []
         results = []
 
-    row_klass = RowClassFactory(columns)
-    
-    return ResultSet(columns, results, row_klass)
+    return ResultSet(columns, results)