--- ZSQLExtend/ZSQLExtend.py 2006/09/17 10:05:03 1.94 +++ ZSQLExtend/ZSQLExtend.py 2006/10/05 09:37:38 1.95 @@ -333,6 +333,66 @@ class ZSQLExtendFolder(Folder,Persistent else: if node[1].nodeName==containerTagName: 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) + zLOG.LOG("import xml",zLOG.INFO,searchStr) + 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) + zLOG.LOG("update xml",zLOG.INFO,queryStr) + 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) + zLOG.LOG("update xml",zLOG.INFO,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')) + + zLOG.LOG("update xml: fieldnames",zLOG.INFO,repr(fieldNames)) + 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: + zLOG.LOG("update xml: fieldname",zLOG.INFO,repr(fieldName)) + if fieldName not in columns: + qstr="""alter table %s add %s %s""" + self.ZSQLSimpleSearch(qstr%(table,fieldName,'text')) + zLOG.LOG("update xml: fieldname add",zLOG.INFO,qstr%(table,fieldName,'text')) #fn=node[1].getAttribute("xml:id") #nf=file("xtf/"+fn+".xtf",'w') #nf.write(""""""+node[1].toxml()+"") @@ -1188,7 +1248,7 @@ class ZSQLExtendFolder(Folder,Persistent if diacritics.get(name,'yes')=='no': """filter diacritische zeichen""" value=unicodedata.normalize('NFKD', value.decode('utf-8')).encode('ASCII', 'ignore') - + if name==iCT+"lop": lop=value elif name==iCT+"table":