gnumed-devel
[Top][All Lists]
Advanced

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

[Gnumed-devel] Kickoff for 2005


From: Ian Haywood
Subject: [Gnumed-devel] Kickoff for 2005
Date: Sun, 02 Jan 2005 16:05:56 +1100
User-agent: Mozilla Thunderbird 0.8 (X11/20041012)


Hope everyone had (or still having!) a nice holiday.

This is a diff to remove the need for gmBusinessDBObject._xmin_refetch_col_pos.

I would also like to propose to get rid of gmGP_Toolbar and just let
notebook widgets define their own second-row toolbar where they require it.
Visually and functionally this will be identical to the status quo, advantages:
        - much cleaner code
        - more portable (gmGP_Toolbar breaks on wx 2.5 and on MS-Windows)
- notebook pages that don't use a toolbar don't waste the space (a minor point, it's only ~25 pixels thick)

Ian Haywood




Index: pycommon/gmBusinessDBObject.py
===================================================================
RCS file: /cvsroot/gnumed/gnumed/gnumed/client/pycommon/gmBusinessDBObject.py,v
retrieving revision 1.6
diff -u -r1.6 gmBusinessDBObject.py
--- pycommon/gmBusinessDBObject.py      20 Dec 2004 16:46:55 -0000      1.6
+++ pycommon/gmBusinessDBObject.py      2 Jan 2005 04:49:48 -0000
@@ -117,11 +117,8 @@
                        # one or multiple "update ... set ..." statements which
                        # actually update the database from the data in 
self._payload,
                        # the last query must refetch the XMIN values needed to 
detect
-                       # concurrent updates
-               self.__class__._xmins_refetch_col_pos
-                       # a dict mapping column names to positions for the last
-                       # query in self.__class__._cmds_store_payload such that
-                       # the XMIN fields in self._payload can be updated
+                       # concurrent updates, their field names had better be 
the same as
+                       # in _cmd_fetch_payload
                self.__class__._updatable_fields
                        # a list of fields available to users via 
object['field']
                self.__class__._service
@@ -337,7 +334,7 @@
                queries = []
                for query in self.__class__._cmds_store_payload:
                        queries.append((query, [params]))
-               successful, data = gmPG.run_commit2(link_obj = conn, queries = 
queries)
+               successful, data = gmPG.run_commit2(link_obj = conn, queries = 
queries, get_col_idx = True)
                if not successful:
                        conn.rollback()
                        conn.close()
@@ -350,16 +347,17 @@
                        conn.close()
                        _log.Log(gmLog.lErr, '[%s:%s]: cannot update instance, 
last query did not return XMIN values' % (self.__class__.__name__, self.pk_obj))
                        return (False, data)
-               row = data[0]
-               for key in self.__class__._xmins_refetch_col_pos.keys():
+               row = data[0][0]
+               _idx = data[1]
+               for key in _idx.keys():
                        try:
-                               self._payload[self._idx[key]] = 
row[self.__class__._xmins_refetch_col_pos[key]]
+                               self._payload[self._idx[key]] = row[_idx[key]]
                        except KeyError:
                                conn.rollback()
                                conn.close()
                                _log.Log(gmLog.lErr, '[%s:%s]: cannot update 
instance, XMIN refetch key mismatch on [%s]' % (self.__class__.__name__, 
self.pk_obj, key))
                                _log.Log(gmLog.lErr, 'payload keys: %s' % 
str(self._idx))
-                               _log.Log(gmLog.lErr, 'XMIN refetch keys: %s' % 
str(self.__class__._xmins_refetch_col_pos.keys()))
+                               _log.Log(gmLog.lErr, 'XMIN refetch keys: %s' % 
str(_idx))
                                _log.Log(gmLog.lErr, params)
                                return (False, data)
                conn.commit()
Index: pycommon/gmPG.py
===================================================================
RCS file: /cvsroot/gnumed/gnumed/gnumed/client/pycommon/gmPG.py,v
retrieving revision 1.37
diff -u -r1.37 gmPG.py
--- pycommon/gmPG.py    20 Dec 2004 16:48:00 -0000      1.37
+++ pycommon/gmPG.py    2 Jan 2005 04:50:01 -0000
@@ -607,7 +607,7 @@
 #      print t2-t1, aQuery
        return 1
 #---------------------------------------------------
-def run_commit2(link_obj=None, queries=None, end_tx=False, max_tries=1, 
extra_verbose=False):
+def run_commit2(link_obj=None, queries=None, end_tx=False, max_tries=1, 
extra_verbose=False, get_col_idx = False):
        """Convenience function for running a transaction
           that is supposed to get committed.
 
@@ -643,6 +643,9 @@
                  error occurrs
                - max_tries is honored if and only if link_obj is a service
                  name such that we have full control over the transaction
+                 
+        <get_col_idx> - if true, returned data will be (data, index) where 
index is a dictionary
+                 mapping field names to column positions
 
        method result:
                - returns a tuple (status, data)
@@ -668,14 +671,14 @@
        # check link_obj
        # is it a cursor ?
        if hasattr(link_obj, 'fetchone') and hasattr(link_obj, 'description'):
-               return __commit2cursor(cursor=link_obj, queries=queries, 
extra_verbose=extra_verbose)
+               return __commit2cursor(cursor=link_obj, queries=queries, 
extra_verbose=extra_verbose, get_col_idx=get_col_idx)
        # is it a connection ?
        if (hasattr(link_obj, 'commit') and hasattr(link_obj, 'cursor')):
-               return __commit2conn(conn=link_obj, queries=queries, 
end_tx=end_tx, extra_verbose=extra_verbose)
+               return __commit2conn(conn=link_obj, queries=queries, 
end_tx=end_tx, extra_verbose=extra_verbose, get_col_idx=get_col_idx)
        # take it to be a service name then
-       return __commit2service(service=link_obj, queries=queries, 
max_tries=max_tries, extra_verbose=extra_verbose)
+       return __commit2service(service=link_obj, queries=queries, 
max_tries=max_tries, extra_verbose=extra_verbose, get_col_idx=get_col_idx)
 #---------------------------------------------------
-def __commit2service(service=None, queries=None, max_tries=1, 
extra_verbose=False):
+def __commit2service(service=None, queries=None, max_tries=1, 
extra_verbose=False, get_col_idx=False):
        # sanity checks
        try: int(max_tries)
        except ValueEror: max_tries = 1
@@ -753,9 +756,12 @@
        conn.commit()
        curs.close()
        conn.close()
-       return (True, data)
+       if get_col_idx:
+               return (True, (data, get_col_indices (curs)))
+       else:
+               return (True, data)
 #---------------------------------------------------
-def __commit2conn(conn=None, queries=None, end_tx=False, extra_verbose=False):
+def __commit2conn(conn=None, queries=None, end_tx=False, extra_verbose=False, 
get_col_idx=False):
        # get cursor
        curs = conn.cursor()
 
@@ -812,7 +818,10 @@
        if end_tx:
                conn.commit()
        curs.close()
-       return (True, data)
+       if get_col_idx:
+               return (True, (data, get_col_indices (curs)))
+       else:
+               return (True, data)
 #---------------------------------------------------
-def __commit2cursor(cursor=None, queries=None, extra_verbose=False):
+def __commit2cursor(curosr=None, queries=None, extra_verbose=False, 
get_col_idx=False):
        # run queries
@@ -862,7 +871,10 @@
                if curs.description is not None:
                        _log.Log(gmLog.lData, 'there seem to be rows but 
fetchall() failed -- DB API violation ?')
                        _log.Log(gmLog.lData, 'rowcount: %s, description: %s' % 
(curs.rowcount, curs.description))
-       return (True, data)
+       if get_col_idx:
+               return (True, (data, get_col_indices (curs)))
+       else:
+               return (True, data)
 #---------------------------------------------------
 def run_commit (link_obj = None, queries = None, return_err_msg = None):
        """Convenience function for running a transaction

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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