Diff for /ZSQLExtend/ZSQLExtend.py between versions 1.78 and 1.79

version 1.78, 2006/01/16 17:32:40 version 1.79, 2006/03/28 19:54:41
Line 19  import os.path Line 19  import os.path
 import os  import os
 from OFS.SimpleItem import SimpleItem  from OFS.SimpleItem import SimpleItem
   
   def getTextFromNode(nodename):
       nodelist=nodename.childNodes
       rc = ""
       for node in nodelist:
           if node.nodeType == node.TEXT_NODE:
              rc = rc + node.data
       return rc
   
       
 def analyseIntSearch(word):  def analyseIntSearch(word):
     #analyse integer searches      #analyse integer searches
   
Line 72  class ZSQLExtendFolder(Folder,Persistent Line 81  class ZSQLExtendFolder(Folder,Persistent
         return sql_quote(str)          return sql_quote(str)
           
           
     def importXMLFile(self,table,containerTagName,file,identify=None,RESPONSE=None):      
       def importXMLFile(self,table,data,identify=None,RESPONSE=None):
         #TODO: finish importXMLFile          #TODO: finish importXMLFile
         '''          '''
         Import XML file into the table          Import XML file into the table
         @param table: name of the table the xml shall be imported into          @param table: name of the table the xml shall be imported into
         @param containerTagName: XML-Tag which describes a dataset          @param containerTagName: XML-Tag which describes a dataset
         @param file: xmlfile handle          @param data: data to be imported
         @param identify: (optional) field res. tag which identifies a entry uniquely for updating purposes.          @param identify: (optional) field res. tag which identifies a entry uniquely for updating purposes.
         @param RESPONSE: (optional)          @param RESPONSE: (optional)
         '''          '''
         from xml.dom.pulldom import parseString          from xml.dom.pulldom import parseString
   
         doc=parseString(file.read())        
           #fh=file("/tmp/fmpxml.xml")
           import bz2
           import base64
           
           ret=""
           data=bz2.decompress(base64.decodestring(data))
           #data=fh.read()
   
           doc=parseString(data)
         while 1:          while 1:
             node=doc.getEvent()              node=doc.getEvent()
                   
             if node is None:              if node is None:
                 break;                  break;
             else:              else:
                 if node[1].nodeName==containerTagName:                  if node[1].nodeName=='ROW':
                     doc.expandNode(node[1])                      doc.expandNode(node[1])
                       cols=node[1].getElementsByTagName('COL')
                       dataSet=[]
                       for col in cols:
                           data=col.getElementsByTagName('DATA')
                           dataSet.append(getTextFromNode(data[0]))
                       update=False
                       if identify:
   
                           nr=fieldNames.index(identify)
                           field=dataSet[nr]
   
                           searchStr="""select %s from %s where %s = '%s'"""%(identify,table,identify,field)
                           search=self.ZSQLSimpleSearch(searchStr)
                           if search:
                               update=True
                       
                       if update:
                           tmp=[]
                           for fieldName in fieldNames:
                               tmp.append("""%s = %s"""%(fieldName,self.ZSQLQuote(dataSet[fieldNames.index(fieldName)])))
                           setStr=",".join(tmp)
                           nr=fieldNames.index(identify)
                           field=dataSet[nr]
                     
                           queryStr="""UPDATE %s SET %s WHERE %s = '%s' """%(table,setStr,identify,field)
                           self.ZSQLSimpleSearch(queryStr)
                           ret+="ud: %s \n"%field
                       else:
   
                          
                           fields=",".join(fieldNames)
                           values=",".join([""" %s """%self.ZSQLQuote(x) for x in dataSet])
                     
                           
                           queryStr="""INSERT INTO %s  (%s) VALUES (%s)"""%(table,fields,values)
                           self.ZSQLSimpleSearch(queryStr)
                           ret+="ad: %s \n"%field
                           
                   elif node[1].nodeName=="METADATA":
                       fieldNames=[]
                       doc.expandNode(node[1])
                   
                       names=node[1].getElementsByTagName('FIELD')
   
                       for name in names:
                           fieldNames.append(name.getAttribute('NAME'))
   
                       qstr="""select attname from pg_attribute, pg_class where attrelid = pg_class.oid and relname = '%s' """
                       columns=[x.attname for x in self.ZSQLSimpleSearch(qstr%table)]
                    
                       for fieldName in fieldNames:
                           if fieldName not in columns:
                               qstr="""alter table %s add %s %s"""
                               self.ZSQLSimpleSearch(qstr%(table,fieldName,'text'))
                     
                 #fn=node[1].getAttribute("xml:id")                  #fn=node[1].getAttribute("xml:id")
                 #nf=file("xtf/"+fn+".xtf",'w')                  #nf=file("xtf/"+fn+".xtf",'w')
                 #nf.write("""<texts xmlns="http://emegir.info/xtf" xmlns:lem="http://emegir.info/lemma" >"""+node[1].toxml()+"</texts>")                  #nf.write("""<texts xmlns="http://emegir.info/xtf" xmlns:lem="http://emegir.info/lemma" >"""+node[1].toxml()+"</texts>")
                 #print "wrote: %s"%fn                  #print "wrote: %s"%fn
                           return ret
                   
     def generateIndex(self,field,index_name,table,RESPONSE=None):      def generateIndex(self,field,index_name,table,RESPONSE=None):
         """erzeuge index aus feld"""          """erzeuge index aus feld"""
Line 455  class ZSQLExtendFolder(Folder,Persistent Line 529  class ZSQLExtendFolder(Folder,Persistent
         except:          except:
             zLOG.LOG("ZSQLResetConnection",zLOG.ERROR, '%s %s'%sys.exc_info()[:2])              zLOG.LOG("ZSQLResetConnection",zLOG.ERROR, '%s %s'%sys.exc_info()[:2])
   
     def ZSQLSimpleSearch(self,query=None,max_rows=1000000):      def ZSQLSimpleSearch(self,query=None,max_rows=1000000,debug=None):
         """simple search"""          """simple search"""
   
   
         if not query:          if not query:
             query=self.query              query=self.query
           
                   if debug:
                   print "DEBUG: ZSQLSimpleSearch:", query
         if (hasattr(self,"_v_searchSQL") and (self._v_searchSQL == None)) or (not hasattr(self,"_v_searchSQL")):          if (hasattr(self,"_v_searchSQL") and (self._v_searchSQL == None)) or (not hasattr(self,"_v_searchSQL")):
                           
             self._v_searchSQL=Shared.DC.ZRDB.DA.DA("_v_searchSQL","_v_searchSQL",self.getConnectionObj().getId(),"var","<dtml-var var>")              self._v_searchSQL=Shared.DC.ZRDB.DA.DA("_v_searchSQL","_v_searchSQL",self.getConnectionObj().getId(),"var","<dtml-var var>")
Line 1114  class ZSQLExtendFolder(Folder,Persistent Line 1190  class ZSQLExtendFolder(Folder,Persistent
             self.REQUEST.SESSION[storename]['searchFields']=searchFields              self.REQUEST.SESSION[storename]['searchFields']=searchFields
             self.REQUEST.SESSION[storename]['searchFieldsOnly']=searchFieldsOnly              self.REQUEST.SESSION[storename]['searchFieldsOnly']=searchFieldsOnly
   
         print query          
         if not NoQuery:          if not NoQuery:
   
             return self.ZSQLQuery(query)              return self.ZSQLQuery(query)

Removed from v.1.78  
changed lines
  Added in v.1.79


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