Diff for /ZSQLExtend/importFMPXML.py between versions 1.16 and 1.21

version 1.16, 2007/12/11 16:21:24 version 1.21, 2008/01/09 14:43:50
Line 19  except: Line 19  except:
   
 fm_ns = 'http://www.filemaker.com/fmpxmlresult'  fm_ns = 'http://www.filemaker.com/fmpxmlresult'
   
 version_string = "V0.5 ROC 11.12.2007"  version_string = "V0.5.1 ROC 9.1.2008"
   
   def unicodify(text, withNone=False):
       """decode str (utf-8 or latin-1 representation) into unicode object"""
       if withNone and text is None:
           return None
       if not text:
           return u""
       if isinstance(text, str):
           try:
               return text.decode('utf-8')
           except:
               return text.decode('latin-1')
       else:
           return text
   
   def utf8ify(text, withNone=False):
       """encode unicode object or string into byte string in utf-8 representation"""
       if withNone and text is None:
           return None
       if not text:
           return ""
       if isinstance(text, str):
           return text
       else:
           return text.encode('utf-8')
   
 def getTextFromNode(nodename):  def getTextFromNode(nodename):
     """get the cdata content of a node"""      """get the cdata content of a node"""
Line 45  def SimpleSearch(curs,query, args=None, Line 70  def SimpleSearch(curs,query, args=None,
     #logger.debug("executing: "+query)      #logger.debug("executing: "+query)
     if ascii:      if ascii:
         # encode all in UTF-8          # encode all in UTF-8
         query = query.encode("UTF-8")          query = utf8ify(query)
         if args is not None:          if args is not None:
             encargs = []              encargs = []
             for a in args:              for a in args:
                 if a is not None:                  encargs.append(utf8ify(a, withNone=True))
                     a = a.encode("UTF-8")  
                 encargs.append(a)  
                           
             args = encargs              args = encargs
   
Line 227  class xml_handler: Line 250  class xml_handler:
         # try to match date style with XML          # try to match date style with XML
         self.db.execute("set datestyle to 'german'")          self.db.execute("set datestyle to 'german'")
                   
         # translate id_field (SQL-name) to XML-name  
         self.xml_id = self.sql_field_map.get(self.id_field, None)  
           
         #self.logger.debug("xml-fieldnames:"+repr(self.xml_field_names))          #self.logger.debug("xml-fieldnames:"+repr(self.xml_field_names))
         # get list of fields and types of db table          # get list of fields and types of db table
         qstr="select attname, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) from pg_attribute, pg_class where attrelid = pg_class.oid and pg_attribute.attnum > 0 and relname = '%s'"          qstr="select attname, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) from pg_attribute, pg_class where attrelid = pg_class.oid and pg_attribute.attnum > 0 and relname = '%s'"
Line 240  class xml_handler: Line 260  class xml_handler:
             #print "SQL fields: %s (%s)"%(n,t)              #print "SQL fields: %s (%s)"%(n,t)
             self.sql_fields[n] = TableColumn(n,t)              self.sql_fields[n] = TableColumn(n,t)
                   
           # translate id_field (SQL-name) to XML-name
           self.xml_id = self.sql_field_map.get(self.id_field, None)
           # get type of id_field
           if self.id_field:
               self.id_type = self.sql_fields[self.id_field].getType()
           else:
               self.id_type = None
           
         # check fields to update          # check fields to update
         if self.update_fields is None:          if self.update_fields is None:
             if self.keep_fields:              if self.keep_fields:
Line 288  class xml_handler: Line 316  class xml_handler:
                     self.db.execute(qstr)                      self.db.execute(qstr)
                     self.dbCon.commit()                      self.dbCon.commit()
                                   
         # prepare sql statements for update          # prepare sql statements for update (do not update id_field)
         setStr=string.join(["%s = %%s"%self.xml_field_map[f] for f in self.xml_update_list], ', ')          setStr=string.join(["%s = %%s"%self.xml_field_map[f] for f in self.xml_update_list if f != self.xml_id], ', ')
         self.updQuery="UPDATE %s SET %s WHERE %s = %%s"%(self.table,setStr,self.id_field)          self.updQuery="UPDATE %s SET %s WHERE %s = %%s"%(self.table,setStr,self.id_field)
         # and insert          # and insert
         fields=string.join([self.xml_field_map[x].getName() for x in self.xml_update_list], ',')          fields=string.join([self.xml_field_map[x].getName() for x in self.xml_update_list], ',')
Line 394  class xml_handler: Line 422  class xml_handler:
         id_val=''          id_val=''
         # synchronize by id_field          # synchronize by id_field
         if self.id_field:          if self.id_field:
               if self.id_type == 'integer':
                   id_val = int(self.xml_data[self.xml_id])
               else:
             id_val = self.xml_data[self.xml_id]              id_val = self.xml_data[self.xml_id]
                   
             if id_val in self.dbIDs:              if id_val in self.dbIDs:
                 self.dbIDs[id_val] += 1                  self.dbIDs[id_val] += 1
                 update=True                  update=True
Line 402  class xml_handler: Line 434  class xml_handler:
         # collect all values          # collect all values
         args = []          args = []
         for fn in self.xml_update_list:          for fn in self.xml_update_list:
               # do not update id_field
               if update and fn == self.xml_id:
                   continue
               
             f = self.xml_field_map[fn]              f = self.xml_field_map[fn]
             val = self.xml_data[fn]              val = self.xml_data[fn]
             type = self.sql_fields[f.getName()].getType()              type = self.sql_fields[f.getName()].getType()

Removed from v.1.16  
changed lines
  Added in v.1.21


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>