Ed Leafe wrote:
In going over some issues with MySQL Time datatypes, I came across a method defined in dBackend.py, and implemented only in dbMySQL.py: getDaboFieldType(). I did a grep on the source code for all of Dabo, and cannot find any place where this is called. Do you remember what it was used for? Is it safe to delete it?

I don't know... I think I thought I was doing something important at the time, but the calls to it from dGrid and dBizobj appear to have vanished. It was revision 1693, here's the info:

[EMAIL PROTECTED]:~/projects/dabo$ svn log -r 1693
------------------------------------------------------------------------
r1693 | paul | 2005-12-14 15:46:55 -0800 (Wed, 14 Dec 2005) | 16 lines

Added functions to dBizobj, dCursor, and dBackend to get the data structure
from the cursor description, instead of querying the backend based on a
table name. This is more likely to contain correct information, but will
need work for other backends besides MySQL. Also, getting the pkid is
still problematic - but IMO it isn't a big deal to just have the user
tell us which field to use as the PK.

Nothing I've done replaces any functionality that already exists.

Fixed dGrid's buildFromDataSet() to use the new function so it will work
even if the bizobj has no records at the time of creation.

Fixed dGrid.sort() to not care if sort is done on an empty bizobj.


[EMAIL PROTECTED]:~/projects/dabo$ svn diff -r 1692:1693
Index: dabo/biz/dBizobj.py
===================================================================
--- dabo/biz/dBizobj.py (revision 1692)
+++ dabo/biz/dBizobj.py (revision 1693)
@@ -1090,6 +1090,16 @@
                return self._CurrentCursor.getFields(self.DataSource)


+       def getDataStructureFromDescription(self):
+ """ Gets the structure of the DataSource table. Returns a list
+               of 3-tuples, where the 3-tuple's elements are:
+                       0: the field name (string)
+ 1: the field type ('I', 'N', 'C', 'M', 'B', 'D', 'T')
+                       2: boolean specifying whether this is a pk field.
+               """
+               return self._CurrentCursor.getFieldInfoFromDescription()
+
+
        def getParams(self):
""" Return the parameters to send to the cursor's execute method.

Index: dabo/db/dBackend.py
===================================================================
--- dabo/db/dBackend.py (revision 1692)
+++ dabo/db/dBackend.py (revision 1693)
@@ -129,7 +129,22 @@
# It will give the field names, but the type info and pk info isn't
                # adequate generically yet.
                return ()
-
+
+
+       def getDaboFieldType(self, backendFieldType):
+ """ Return the Dabo code (I, T, D, ...) for the passed backend Field Type.
+
+               If it can't be determined, the field type will be '?'.
+               """
+               return "?"
+
+
+       def getFieldInfoFromDescription(self, cursorDescription):
+               """ Return field information from the cursor description."""
+ # Default: return all the field names and "?", None for type and pkid. + return tuple([(d[0], self.getDaboFieldType(d[1]), None) for d in cursorDescription])
+
+
        def beginTransaction(self, cursor):
                """ Begin a SQL transaction."""
                try:
Index: dabo/db/dbMySQL.py
===================================================================
--- dabo/db/dbMySQL.py  (revision 1692)
+++ dabo/db/dbMySQL.py  (revision 1693)
@@ -125,7 +125,46 @@

                        fields.append((name.strip(), ft, pk))
                return tuple(fields)
+
+
+       def getDaboFieldType(self, backendFieldType):
+               import MySQLdb.constants.FIELD_TYPE as ftypes
+               typeMapping = {}
+               for i in dir(ftypes):
+                       if i[0] != "_":
+                               v = getattr(ftypes, i)
+                               typeMapping[v] = i

+               daboMapping = {"BLOB": "M",
+                               "CHAR": "C",
+                               "DATE": "D",
+                               "DATETIME": "T",
+                               "DECIMAL": "N",
+                               "DOUBLE": "I",
+                               "ENUM": "C",
+                               "FLOAT": "N",
+                               "GEOMETRY": "?",
+                               "INT24": "I",
+                               "INTERVAL": "?",
+                               "LONG": "I",
+                               "LONGLONG": "I",
+                               "LONG_BLOB": "M",
+                               "MEDIUM_BLOB": "M",
+                               "NEWDATE": "?",
+                               "NULL": "?",
+                               "SET": "?",
+                               "SHORT": "I",
+                               "STRING": "C",
+                               "TIME": "?",
+                               "TIMESTAMP": "?",
+                               "TINY": "I",
+                               "TINY_BLOB": "M",
+                               "VAR_STRING": "C",
+                               "YEAR": "?"}
+
+               return daboMapping[typeMapping[backendFieldType]]
+
+
        def beginTransaction(self, cursor):
                """ Begin a SQL transaction."""
                if self.useTransactions:
Index: dabo/db/dCursorMixin.py
===================================================================
--- dabo/db/dCursorMixin.py     (revision 1692)
+++ dabo/db/dCursorMixin.py     (revision 1693)
@@ -1273,7 +1273,18 @@
                        tableName = self.Table
                return self.BackendObject.getFields(tableName)

-
+
+       def getFieldInfoFromDescription(self):
+               """ Get field information from the cursor description.
+
+ Returns a tuple of 3-tuples, where the 3-tuple's elements are:
+                       0: the field name (string)
+ 1: the field type ('I', 'N', 'C', 'M', 'B', 'D', 'T'), or None. + 2: boolean specifying whether this is a pk field, or None.
+               """
+ return self.BackendObject.getFieldInfoFromDescription(self.description)
+
+
        def getLastInsertID(self):
                """ Return the most recently generated PK """
                ret = None
Index: dabo/ui/uiwx/dGrid.py
===================================================================
--- dabo/ui/uiwx/dGrid.py       (revision 1692)
+++ dabo/ui/uiwx/dGrid.py       (revision 1693)
@@ -1527,7 +1527,8 @@
                                        break
                        if sortCol is not None:
                                self.CurrentColumn = sortCol
-                               self.processSort(sortCol, toggleSort=False)
+                               if self.RowCount > 0:
+ self.processSort(sortCol, toggleSort=False)


        def _addEmptyRows(self):
@@ -1605,7 +1606,14 @@
                        if data:
                                firstRec = data[0]
                        else:
-                               return False
+ # Ok, the bizobj doesn't have any records, yet we still want to build + # the grid. We can get enough info from getDataStructureFromDescription(): + structure = bizobj.getDataStructureFromDescription()
+                               firstRec = {}
+                               for field in structure:
+                                       firstRec[field[0]] = None
+                                       if not colTypes.has_key(field[0]):
+ colTypes[field[0]] = field[1]
                else:
                        # not a bizobj datasource
                        firstRec = ds[0]
@@ -1981,7 +1989,11 @@
                        self.sort()
                elif biz:
                        # Use the default sort() in the bizobj:
- biz.sort(columnToSort, sortOrder, self.caseSensitiveSorting)
+                       try:
+ biz.sort(columnToSort, sortOrder, self.caseSensitiveSorting)
+                       except dException.NoRecordsException:
+                               # no records to sort: who cares.
+                               pass
                else:
                        # Create the list to hold the rows for sorting
                        caseSensitive = self.caseSensitiveSorting
[EMAIL PROTECTED]:~/projects/dabo$



--
Paul McNett
http://paulmcnett.com
http://dabodev.com


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to