Changeset 325

Show
Ignore:
Timestamp:
06/12/2004 11:27:04 AM (5 years ago)
Author:
paul
Message:

Change default params value to the empty tuple in dBizobj. Since different
backends expect different types for the params arg, modify dCursorMixin.execute
to not send the params arg at all if it is None or otherwise empty. Tested with
MySQL and Firebird: Ok.

Modified dbFirebird's getCursor() to do the required mixing-in and to return
a full Dabo cursor instance. dbFirebird now gets past all the initial errors
in my wiz-generated test app. Next up: there is MySQL-specific code in my
dPageDataNav code - dbFirebird is currently choking on the LIMIT clause.

Modified dProgressDialog to properly react to exceptions that happen in the
passed function. It used to be that if an exception happened in the requery()
code, the dProgressDialog wouldn't handle it and therefore the worker thread
would never return control back to the main thread. Now, control is returned
and the main thread tries to show useful information about the exception. It
is a start at least.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/biz/dBizobj.py

    r324 r325  
    2828        self.__currentCursorKey = None 
    2929        self._conn = conn 
    30         self.__params = None      # tuple of params to be merged with the sql in the cursor 
     30        self.__params = ()        # tuple of params to be merged with the sql in the cursor 
    3131        self.__children = []        # Collection of child bizobjs 
    3232        self._baseClass = dBizobj 
  • trunk/db/dBackend.py

    r324 r325  
    7878        See dCursorMixin.getFields() for a description of the return value.          
    7979        """ 
     80        # It is too bad, but dbapi2.0's cursor().description doesn't cut it. 
     81        # It will give the field names, but the type info and pk info isn't 
     82        # adequate generically yet. 
    8083        return () 
    8184         
  • trunk/db/dCursorMixin.py

    r320 r325  
    100100        method will detect that, and convert the results to a dictionary. 
    101101        """ 
    102         res = self.superCursor.execute(self, sql, params) 
     102        if params is None or len(params) == 0: 
     103            res = self.superCursor.execute(self, sql) 
     104        else: 
     105            res = self.superCursor.execute(self, sql, params) 
    103106        self._records = self.fetchall() 
    104107 
  • trunk/db/dbFirebird.py

    r324 r325  
     1import datetime 
     2import kinterbasdb 
    13from dBackend import dBackend 
    2 import datetime 
     4from dCursorMixin import dCursorMixin 
     5from dSqlBuilderMixin import dSqlBuilderMixin 
    36 
    47class Firebird(dBackend): 
     
    811 
    912    def getConnection(self, connectInfo): 
    10         import kinterbasdb 
    11  
    1213        # Port doesn't seem to work, but I need to research... for now it's disabled. 
    1314#       port = connectInfo.Port 
     
    2728         
    2829    def getDictCursorClass(self): 
    29         import kinterbasdb 
    3030        return kinterbasdb.Cursor 
    3131 
     32     
    3233    def getCursor(self, cursorClass): 
    33         return self._connection.cursor() 
     34        dbCursorClass = self.getDictCursorClass() 
     35        connection = self._connection 
     36        backendObject = self 
     37        class dCursor(dCursorMixin, dbCursorClass, dSqlBuilderMixin): 
     38            def __init__(self): 
     39                dCursorMixin.__init__(self) 
     40                dbCursorClass.__init__(self, connection) 
     41                dSqlBuilderMixin.__init__(self) 
     42                self.superCursor = dbCursorClass 
     43                self.BackendObject = backendObject 
     44 
     45        return dCursor() 
     46         
    3447 
    3548    def formatDateTime(self, val): 
  • trunk/ui/uiwx/classes/dProgressDialog.py

    r232 r325  
    3030from threading import * 
    3131import wx 
    32 import time 
     32import dMessageBox 
    3333 
    3434ID_CANCEL = wx.NewId() 
    3535EVT_RESULT_ID = wx.NewId() 
     36EVT_EXCEPTION_ID = wx.NewId() 
    3637 
    3738def EVT_RESULT(win, func): 
    3839    win.Connect(-1, -1, EVT_RESULT_ID, func) 
     40 
     41def EVT_EXCEPTION(win, func): 
     42    win.Connect(-1, -1, EVT_EXCEPTION_ID, func) 
    3943 
    4044class ResultEvent(wx.PyEvent): 
     
    4549        wx.PyEvent.__init__(self) 
    4650        self.SetEventType(EVT_RESULT_ID) 
     51        self.response = response 
     52 
     53class ExceptionEvent(wx.PyEvent): 
     54    """ Simple event to carry arbitrary result data. 
     55    """ 
     56 
     57    def __init__(self, response): 
     58        wx.PyEvent.__init__(self) 
     59        self.SetEventType(EVT_EXCEPTION_ID) 
    4760        self.response = response 
    4861 
     
    6376 
    6477    def run(self): 
    65         response = self._func() 
    66         # Done, send notify: 
    67         wx.PostEvent(self._notify_window,ResultEvent(response)) 
     78        try: 
     79            response = self._func() 
     80            # Done, send notify: 
     81            wx.PostEvent(self._notify_window,ResultEvent(response)) 
     82        except Exception, e: 
     83            wx.PostEvent(self._notify_window,ExceptionEvent(e)) 
    6884 
    6985# GUI Frame class that spins off the worker thread 
     
    8197        # Set up event handler for any worker thread results 
    8298        EVT_RESULT(self, self.OnResult) 
     99        EVT_EXCEPTION(self, self.OnException) 
    83100 
    84101        # And indicate we don't have a worker thread yet 
     
    98115        self.Hide() 
    99116 
     117    def OnException(self, event): 
     118        dMessageBox.stop("Error encountered:\n\n%s" % str(event.response)) 
     119        self.Hide() 
     120     
    100121    def OnClose(self, event): 
    101122        # Don't let the window close.