version 1.102, 2007/02/09 17:39:44
|
version 1.103, 2007/02/20 16:00:03
|
Line 424 class ZSQLExtendFolder(Folder,Persistent
|
Line 424 class ZSQLExtendFolder(Folder,Persistent
|
|
|
if data: |
if data: |
data=bz2.decompress(base64.decodestring(data)) |
data=bz2.decompress(base64.decodestring(data)) |
zLOG.LOG("fmpxml",zLOG.INFO,"received file") |
logger("fmpxml",logging.INFO,"received file") |
doc=parseString(data) |
doc=parseString(data) |
zLOG.LOG("fmpxml",zLOG.INFO,"parsed file") |
logger("fmpxml",logging.INFO,"parsed file") |
|
|
elif filename: |
elif filename: |
fh=file(filename) |
fh=file(filename) |
zLOG.LOG("fmpxml",zLOG.INFO,"reading file") |
logger("fmpxml",logging.INFO,"reading file") |
doc=parse(fh) |
doc=parse(fh) |
zLOG.LOG("fmpxml",zLOG.INFO,"parsed file") |
logger("fmpxml",logging.INFO,"parsed file") |
|
|
dbIDs = {} |
dbIDs = {} |
rowcnt = 0 |
rowcnt = 0 |
Line 445 class ZSQLExtendFolder(Folder,Persistent
|
Line 445 class ZSQLExtendFolder(Folder,Persistent
|
dbIDs[id[0]] = 0; |
dbIDs[id[0]] = 0; |
rowcnt += 1 |
rowcnt += 1 |
|
|
zLOG.LOG("fmpxml",zLOG.INFO,"%d entries in DB to sync"%rowcnt) |
logger("fmpxml",logging.INFO,"%d entries in DB to sync"%rowcnt) |
|
|
fieldNames = [] |
fieldNames = [] |
rowcnt = 0 |
rowcnt = 0 |
Line 471 class ZSQLExtendFolder(Folder,Persistent
|
Line 471 class ZSQLExtendFolder(Folder,Persistent
|
# update all fields |
# update all fields |
update_fields = fieldNames |
update_fields = fieldNames |
|
|
zLOG.LOG("fmpxml fieldnames:",zLOG.INFO,repr(fieldNames)) |
logger("fmpxml fieldnames:",logging.INFO,repr(fieldNames)) |
# get list of fields in db table |
# get list of fields in db table |
qstr="""select attname from pg_attribute, pg_class where attrelid = pg_class.oid and relname = '%s'""" |
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)] |
columns=[x.attname for x in self.ZSQLSimpleSearch(qstr%table)] |
|
|
# adjust db table to fields in XML and fieldlist |
# adjust db table to fields in XML and fieldlist |
for fieldName in fieldNames: |
for fieldName in fieldNames: |
zLOG.LOG("fmpxml fieldname:",zLOG.INFO,repr(fieldName)) |
logger("fmpxml fieldname:",logging.INFO,repr(fieldName)) |
if (fieldName not in columns) and (fieldName in update_fields): |
if (fieldName not in columns) and (fieldName in update_fields): |
qstr="""alter table %s add %s %s""" |
qstr="""alter table %s add %s %s""" |
self.ZSQLSimpleSearch(qstr%(table,fieldName,'text')) |
self.ZSQLSimpleSearch(qstr%(table,fieldName,'text')) |
zLOG.LOG("fmpxml add field:",zLOG.INFO,qstr%(table,fieldName,'text')) |
logger("fmpxml add field:",logging.INFO,qstr%(table,fieldName,'text')) |
|
|
# ROW tags (in RESULTSET tag) hold data |
# ROW tags (in RESULTSET tag) hold data |
elif node[1].nodeName == 'ROW': |
elif node[1].nodeName == 'ROW': |
Line 515 class ZSQLExtendFolder(Folder,Persistent
|
Line 515 class ZSQLExtendFolder(Folder,Persistent
|
setStr=string.join(setvals, ',') |
setStr=string.join(setvals, ',') |
id_val=dataSet[id_field] |
id_val=dataSet[id_field] |
qstr="""UPDATE %s SET %s WHERE %s = '%s' """%(table,setStr,id_field,id_val) |
qstr="""UPDATE %s SET %s WHERE %s = '%s' """%(table,setStr,id_field,id_val) |
#zLOG.LOG("fmpxml update:",zLOG.INFO,queryStr) |
#logger("fmpxml update:",logging.INFO,queryStr) |
self.ZSQLSimpleSearch(qstr) |
self.ZSQLSimpleSearch(qstr) |
ret+="up: %s \n"%id_val |
ret+="up: %s \n"%id_val |
else: |
else: |
Line 524 class ZSQLExtendFolder(Folder,Persistent
|
Line 524 class ZSQLExtendFolder(Folder,Persistent
|
values=string.join([" %s "%self.ZSQLQuote(dataSet[x]) for x in update_fields], ',') |
values=string.join([" %s "%self.ZSQLQuote(dataSet[x]) for x in update_fields], ',') |
qstr="""INSERT INTO %s (%s) VALUES (%s)"""%(table,fields,values) |
qstr="""INSERT INTO %s (%s) VALUES (%s)"""%(table,fields,values) |
self.ZSQLSimpleSearch(qstr) |
self.ZSQLSimpleSearch(qstr) |
#zLOG.LOG("fmpxml: insert",zLOG.INFO,queryStr) |
#logger("fmpxml: insert",logging.INFO,queryStr) |
ret+="ad: %s \n"%dataSet.get(id_field, rowcnt) |
ret+="ad: %s \n"%dataSet.get(id_field, rowcnt) |
|
|
#zLOG.LOG("fmpxml row:",zLOG.INFO,"%d (%s)"%(rowcnt,id_val)) |
#logger("fmpxml row:",logging.INFO,"%d (%s)"%(rowcnt,id_val)) |
if (rowcnt % 10) == 0: |
if (rowcnt % 10) == 0: |
zLOG.LOG("fmpxml row:",zLOG.INFO,"%d (%s)"%(rowcnt,id_val)) |
logger("fmpxml row:",logging.INFO,"%d (%s)"%(rowcnt,id_val)) |
transaction.commit() |
transaction.commit() |
|
|
transaction.commit() |
transaction.commit() |
Line 538 class ZSQLExtendFolder(Folder,Persistent
|
Line 538 class ZSQLExtendFolder(Folder,Persistent
|
for id in dbIDs.keys(): |
for id in dbIDs.keys(): |
# find all not-updated fields |
# find all not-updated fields |
if dbIDs[id] == 0: |
if dbIDs[id] == 0: |
zLOG.LOG("fmpxml delete:",zLOG.INFO,id) |
logger("fmpxml delete:",logging.INFO,id) |
qstr = "DELETE FROM %s WHERE %s = '%s'" |
qstr = "DELETE FROM %s WHERE %s = '%s'" |
self.ZSQLSimpleSearch(qstr%(table,id_field,id)) |
self.ZSQLSimpleSearch(qstr%(table,id_field,id)) |
|
|
elif dbIDs[id] > 1: |
elif dbIDs[id] > 1: |
zLOG.LOG("fmpxml sync:",zLOG.INFO,"id used more than once?"+id) |
logger("fmpxml sync:",logging.INFO,"id used more than once?"+id) |
|
|
transaction.commit() |
transaction.commit() |
|
|
Line 717 class ZSQLExtendFolder(Folder,Persistent
|
Line 717 class ZSQLExtendFolder(Folder,Persistent
|
#print "field",field |
#print "field",field |
if not field: |
if not field: |
return 1 |
return 1 |
if field=="": |
if field.strip()=="": |
return 1 |
return 1 |
return 0 |
return 0 |
|
|
Line 818 class ZSQLExtendFolder(Folder,Persistent
|
Line 818 class ZSQLExtendFolder(Folder,Persistent
|
for result in results: |
for result in results: |
field=getattr(result,fieldName) |
field=getattr(result,fieldName) |
fieldValue=getattr(result,valueName) |
fieldValue=getattr(result,valueName) |
|
|
if fieldValue: |
if fieldValue: |
|
|
if not linelen: |
if not linelen: |
Line 1295 class ZSQLExtendFolder(Folder,Persistent
|
Line 1296 class ZSQLExtendFolder(Folder,Persistent
|
|
|
|
|
arg=argTmp[0:] |
arg=argTmp[0:] |
if arg[0]=="_":arg="-"+argTmp[1:] # aender _ in - als standard |
|
|
|
if arg not in queryList: # noch nicht drin |
if arg not in queryList: # noch nicht drin |
querys.append("%s=%s"%(arg,argv[argTmp])) |
querys.append("%s=%s"%(arg,argv[argTmp])) |
Line 1344 class ZSQLExtendFolder(Folder,Persistent
|
Line 1345 class ZSQLExtendFolder(Folder,Persistent
|
searchFields={} |
searchFields={} |
searchFieldsOnly={} |
searchFieldsOnly={} |
queryTemplate=[] |
queryTemplate=[] |
|
outerjoin="" |
|
|
if not select: |
if not select: |
select="oid,*" |
select="oid,*" |
Line 1429 class ZSQLExtendFolder(Folder,Persistent
|
Line 1431 class ZSQLExtendFolder(Folder,Persistent
|
skip="OFFSET "+str(value) |
skip="OFFSET "+str(value) |
rangeStart=str(value) |
rangeStart=str(value) |
elif name==iCT+"join": |
elif name==iCT+"join": |
|
|
whereList.append(value) |
whereList.append(value) |
|
elif name==iCT+"outerjoin": |
|
|
|
outerjoin=value |
elif name==iCT+"sort": |
elif name==iCT+"sort": |
sortstrs=[] |
sortstrs=[] |
|
|
for word in value.split(','): |
for word in value.split(','): |
wordstr=word.lstrip().rstrip() |
wordstr=word.lstrip().rstrip() |
if sortAllFields: |
if sortAllFields: |
Line 1584 class ZSQLExtendFolder(Folder,Persistent
|
Line 1591 class ZSQLExtendFolder(Folder,Persistent
|
|
|
#print "QE",table |
#print "QE",table |
#print (select,table,where,sort,maxstr,skip) |
#print (select,table,where,sort,maxstr,skip) |
query="SELECT %s FROM %s %s %s %s %s"%(select,table,where,sort,maxstr,skip) |
query="SELECT %s FROM %s %s %s %s %s %s"%(select,table,outerjoin,where,sort,maxstr,skip) |
|
|
if not nostore=="yes": |
if not nostore=="yes": |
|
|