commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r7328 - in trunk/gnue-common/src/datasources/drivers: Base DBSIG2


From: reinhard
Subject: [gnue] r7328 - in trunk/gnue-common/src/datasources/drivers: Base DBSIG2 appserver/appserver file
Date: Fri, 8 Apr 2005 18:37:48 -0500 (CDT)

Author: reinhard
Date: 2005-04-08 18:37:46 -0500 (Fri, 08 Apr 2005)
New Revision: 7328

Modified:
   trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py
   trunk/gnue-common/src/datasources/drivers/file/Base.py
Log:
Cleaned up support for distinct, added a few comments.


Modified: trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/DataObject.py        
2005-04-08 23:14:36 UTC (rev 7327)
+++ trunk/gnue-common/src/datasources/drivers/Base/DataObject.py        
2005-04-08 23:37:46 UTC (rev 7328)
@@ -42,6 +42,7 @@
     self._connection = connection
 
     self.table = None
+    self.distinct = False
 
     self.masterlink = ""
     self.detaillink = ""
@@ -95,7 +96,8 @@
                        table      = self.table,
                        fieldnames = self._fieldReferences.keys (),
                        condition  = GConditions.buildCondition (conditions),
-                       sortorder  = self.sorting and self.sorting or [])
+                       sortorder  = self.sorting and self.sorting or [],
+                       distinct   = self.distinct)
 
     elif self._dataSource.type == 'static':
       resultset.query ('static', data = self._staticSet.data)

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py       
2005-04-08 23:14:36 UTC (rev 7327)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py       
2005-04-08 23:37:46 UTC (rev 7328)
@@ -28,6 +28,11 @@
 
 from gnue.common.datasources.drivers import Base
 
+
+# =============================================================================
+# Generic DBSIG2 connection class
+# =============================================================================
+
 class ResultSet (Base.ResultSet):
   """
   Implementation of the ResultSet object for DBSIG2 based drivers.
@@ -37,17 +42,10 @@
   # Build the query string
   # ---------------------------------------------------------------------------
 
-  def __buildQuery (self, table, fieldnames, where, sortorder):
+  def __buildQuery (self, table, what, where, sortorder):
 
-    if self._dataObject.distinct:
-      distinct = 'DISTINCT '
-    else:
-      distinct = ''
+    query = 'SELECT ' + what + ' FROM ' + table
 
-    query = 'SELECT %s%s' % (distinct, string.join (fieldnames, ', '))
-
-    query += ' FROM ' + table
-
     if where:
       query += ' WHERE ' + where
 
@@ -70,17 +68,10 @@
   # Build the query string for the count
   # ---------------------------------------------------------------------------
 
-  def __buildQueryCount (self, table, fieldnames, where):
+  def __buildQueryCount (self, table, what, where):
 
-    if self._dataObject.distinct:
-      distinct = 'DISTINCT '
-    else:
-      distinct = ''
+    query = 'SELECT COUNT (' + what + ') FROM ' + table
 
-    query = 'SELECT COUNT (%s%s)' % (distinct, string.join (fieldnames, ', '))
-
-    query += ' FROM ' + table
-
     if where:
       query += ' WHERE ' + where
 
@@ -88,43 +79,68 @@
 
 
   # ---------------------------------------------------------------------------
-  # Implementation of virtual methods
+  # Execute query for object type datasources
   # ---------------------------------------------------------------------------
 
-  def _query_object (self, connection, table, fieldnames, condition, 
sortorder):
+  def _query_object (self, connection, table, fieldnames, condition, sortorder,
+                     distinct):
+
     params = {}
+    what = string.join (fieldnames, ', ')
+    if distinct:
+      what = 'DISTINCT ' + what
     where = condition.asSQL (params)
-    query = self.__buildQuery (table, fieldnames, where, sortorder)
+
+    query = self.__buildQuery (table, what, where, sortorder)
     self.__cursor = connection.makecursor (query, params)
+
     if connection._broken_rowcount:
-      query = self.__buildQueryCount (table, fieldnames, where)
+      query = self.__buildQueryCount (table, what, where)
       self.__count = connection.sql1 (query, params)
     else:
       self.__count = self.__cursor.rowcount
+
     self.__connection = connection
     self.__fieldnames = fieldnames
 
+
   # ---------------------------------------------------------------------------
+  # Execute query for SQL type datasources
+  # ---------------------------------------------------------------------------
 
   def _query_sql (self, connection, sql):
+
     self.__cursor = connection.makecursor (sql)
+
     if connection._broken_rowcount:
       self.__count = 0                  # No chance to find it out
     else:
       self.__count = self.__cursor.rowcount
+
     self.__connection = connection
+
+    # get field names from cursor description
     self.__fieldnames = [(unicode (d [0], connection._encoding)).lower () \
                          for d in self.__cursor.description]
 
   # ---------------------------------------------------------------------------
+  # Return result count
+  # ---------------------------------------------------------------------------
 
   def _count (self):
+
     return self.__count
 
+
   # ---------------------------------------------------------------------------
+  # Yield data of next record
+  # ---------------------------------------------------------------------------
 
   def _fetch (self, cachesize):
+
     while True:
+
+      # fetch next records from the backend
       if self.__connection._broken_fetchmany:
         try:
           rows = self.__cursor.fetchmany (cachesize)
@@ -132,8 +148,12 @@
           break
       else:
         rows = self.__cursor.fetchmany (cachesize)
+
+      # did we receive any?
       if not rows:
         break
+
+      # convert String to Unicode and yield a dictionary
       for row in rows:
         result = {}
         for (fieldname, value) in zip (self.__fieldnames, row):
@@ -142,7 +162,11 @@
           result [fieldname] = value
         yield result
 
+
   # ---------------------------------------------------------------------------
+  # Close cursor
+  # ---------------------------------------------------------------------------
 
   def _close (self):
+
     self.__cursor.close ()

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py  
2005-04-08 23:14:36 UTC (rev 7327)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py  
2005-04-08 23:37:46 UTC (rev 7328)
@@ -36,15 +36,16 @@
   # Implementation of virtual methods
   # ---------------------------------------------------------------------------
 
-  def _query_object (self, connection, table, fieldnames, condition, 
sortorder):
+  def _query_object (self, connection, table, fieldnames, condition, sortorder,
+                     distinct):
     self.__sm = connection._sm
     self.__session_id = connection._sess_id
     self.__list_id = self.__sm.request (self.__session_id, table,
                                         condition.prefixNotation (), sortorder,
                                         fieldnames)
     self.__fieldnames = fieldnames
+    self.__distinct   = distinct        # currently not honored
 
-
   # ---------------------------------------------------------------------------
 
   def _count (self):

Modified: trunk/gnue-common/src/datasources/drivers/file/Base.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/file/Base.py      2005-04-08 
23:14:36 UTC (rev 7327)
+++ trunk/gnue-common/src/datasources/drivers/file/Base.py      2005-04-08 
23:37:46 UTC (rev 7328)
@@ -85,11 +85,13 @@
   # Implementation of virtual methods
   # ---------------------------------------------------------------------------
 
-  def _query_object (self, connection, table, fieldnames, condition, 
sortorder):
+  def _query_object (self, connection, table, fieldnames, condition, sortorder,
+                     distinct):
     self.__data = connection.getFile (table)
     self.__fieldnames = fieldnames
-    self.__condition = condition        # currently not honored
-    self.__sortorder = sortorder        # currently not honored
+    self.__condition  = condition       # currently not honored
+    self.__sortorder  = sortorder       # currently not honored
+    self.__distinct   = distinct        # currently not honored
 
   # ---------------------------------------------------------------------------
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]