|
|
| version 1.34, 2004/09/27 18:51:57 | version 1.36, 2004/09/27 20:43:58 |
|---|---|
| Line 5 from Globals import DTMLFile | Line 5 from Globals import DTMLFile |
| import urllib | import urllib |
| import re | import re |
| import string | import string |
| from pyPgSQL import libpq | #from pyPgSQL import libpq |
| from AccessControl import getSecurityManager | from AccessControl import getSecurityManager |
| import os.path | import os.path |
| from Products.PageTemplates.PageTemplateFile import PageTemplateFile | from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
| Line 13 from Products.PageTemplates.PageTemplate | Line 13 from Products.PageTemplates.PageTemplate |
| from Products.ZSQLMethods.SQL import SQLConnectionIDs | from Products.ZSQLMethods.SQL import SQLConnectionIDs |
| import Shared.DC.ZRDB.DA | import Shared.DC.ZRDB.DA |
| def sql_quote(self, v): | |
| # quote dictionary | |
| quote_dict = {"\'": "''", "\\": "\\\\"} | |
| for dkey in quote_dict.keys(): | |
| if find(v, dkey) >= 0: | |
| v=join(split(v,dkey),quote_dict[dkey]) | |
| return "'%s'" % v | |
| def showSQLConnectionIDs(self): | def showSQLConnectionIDs(self): |
| return SQLConnectionIDs(self) | return SQLConnectionIDs(self) |
| Line 294 class ZSQLExtendFolder(Folder,Persistent | Line 302 class ZSQLExtendFolder(Folder,Persistent |
| valueList=[] | valueList=[] |
| for x in addList.keys(): | for x in addList.keys(): |
| keyList.append("\""+x+"\"") | keyList.append("\""+x+"\"") |
| valueList.append(libpq.PgQuoteString(addList[x])) | valueList.append(sql_quote(addList[x])) |
| keyString=string.join(keyList,",") | keyString=string.join(keyList,",") |
| valueString=string.join(valueList,",") | valueString=string.join(valueList,",") |
| Line 304 class ZSQLExtendFolder(Folder,Persistent | Line 312 class ZSQLExtendFolder(Folder,Persistent |
| return self.REQUEST.RESPONSE.redirect(format) | return self.REQUEST.RESPONSE.redirect(format) |
| def ZSQLChange(self,**argv): | def ZSQLChange(self,**argv): |
| """Ändern von Einträgen""" | """change entries""" |
| #qs=self.REQUEST['QUERY_STRING'] | #qs=self.REQUEST['QUERY_STRING'] |
| # very bad hack | # very bad hack |
| qs_temp=[] | qs_temp=[] |
| Line 327 class ZSQLExtendFolder(Folder,Persistent | Line 335 class ZSQLExtendFolder(Folder,Persistent |
| table=urllib.unquote(value) | table=urllib.unquote(value) |
| elif name=="-identify": | elif name=="-identify": |
| identify=urllib.unquote(value) | identify=urllib.unquote(value) |
| identify=identify.split("=")[0]+"="+libpq.PgQuoteString(identify.split("=")[1]) | identify=identify.split("=")[0]+"="+sql_quote(identify.split("=")[1]) |
| elif name=="-format": | elif name=="-format": |
| format=urllib.unquote(value) | format=urllib.unquote(value) |
| elif (not name[0]=="-") and (not len(value)==0): | elif (not name[0]=="-") and (not len(value)==0): |
| changeList.append("\""+name+"\"="+libpq.PgQuoteString(urllib.unquote(value))) | changeList.append("\""+name+"\"="+sql_quote(urllib.unquote(value))) |
| changeString=string.join(changeList,",") | changeString=string.join(changeList,",") |
| queryString="UPDATE %s SET %s WHERE %s"%(table,changeString,identify) | queryString="UPDATE %s SET %s WHERE %s"%(table,changeString,identify) |
| self.ZSQLSimpleSearch(queryString) | self.ZSQLSimpleSearch(queryString) |
| return self.REQUEST.RESPONSE.redirect(format) | return self.REQUEST.RESPONSE.redirect(format) |
| def ZSQLChange_old(self): | def ZSQLChange_old(self): |
| """Ändern von Einträgen""" | """change entries""" |
| qs=self.REQUEST['QUERY_STRING'] | qs=self.REQUEST['QUERY_STRING'] |
| #print "CHANGE QS",self.REQUEST | #print "CHANGE QS",self.REQUEST |
| #return self.REQUEST | #return self.REQUEST |
| Line 352 class ZSQLExtendFolder(Folder,Persistent | Line 360 class ZSQLExtendFolder(Folder,Persistent |
| table=urllib.unquote(value) | table=urllib.unquote(value) |
| elif name=="-identify": | elif name=="-identify": |
| identify=urllib.unquote(value) | identify=urllib.unquote(value) |
| identify=identify.split("=")[0]+"="+libpq.PgQuoteString(identify.split("=")[1]) | identify=identify.split("=")[0]+"="+sql_quote(identify.split("=")[1]) |
| elif name=="-format": | elif name=="-format": |
| format=urllib.unquote(value) | format=urllib.unquote(value) |
| elif (not name[0]=="-") and (not len(value)==0): | elif (not name[0]=="-") and (not len(value)==0): |
| changeList.append("\""+name+"\"="+libpq.PgQuoteString(urllib.unquote(value))) | changeList.append("\""+name+"\"="+sql_quote(urllib.unquote(value))) |
| changeString=string.join(changeList,",") | changeString=string.join(changeList,",") |
| queryString="UPDATE %s SET %s WHERE %s"%(table,changeString,identify) | queryString="UPDATE %s SET %s WHERE %s"%(table,changeString,identify) |
| self.ZSQLSimpleSearch(queryString) | self.ZSQLSimpleSearch(queryString) |
| Line 556 class ZSQLExtendFolder(Folder,Persistent | Line 564 class ZSQLExtendFolder(Folder,Persistent |
| except: | except: |
| value="" | value="" |
| #value=libpq.PgQuoteString(value) | #value=sql_quote(value) |
| if name==iCT+"lop": | if name==iCT+"lop": |
| Line 606 class ZSQLExtendFolder(Folder,Persistent | Line 614 class ZSQLExtendFolder(Folder,Persistent |
| namealt=name | namealt=name |
| name="LOWER("+name+")" | name="LOWER("+name+")" |
| if op=="ct": | if op=="ct": |
| tmp=(name+" LIKE "+libpq.PgQuoteString("%"+value+"%")) | tmp=(name+" LIKE "+sql_quote("%"+value+"%")) |
| elif op=="gt": | elif op=="gt": |
| tmp=(name+">"+libpq.PgQuoteString(value)) | tmp=(name+">"+sql_quote(value)) |
| elif op=="lt": | elif op=="lt": |
| tmp=(name+"<"+libpq.PgQuoteString(value)) | tmp=(name+"<"+sql_quote(value)) |
| elif op=="eq": | elif op=="eq": |
| tmp=(name+"="+libpq.PgQuoteString(value)) | tmp=(name+"="+sql_quote(value)) |
| elif op=="bw": | elif op=="bw": |
| tmp=(name+" LIKE "+libpq.PgQuoteString(value+"%")) | tmp=(name+" LIKE "+sql_quote(value+"%")) |
| elif op=="ew": | elif op=="ew": |
| tmp=(name+" LIKE "+libpq.PgQuoteString("%"+value)) | tmp=(name+" LIKE "+sql_quote("%"+value)) |
| elif op=="all": | elif op=="all": |
| tmps=[] | tmps=[] |
| for word in value.split(" "): | for word in value.split(" "): |
| tmps.append(name+" LIKE "+libpq.PgQuoteString("%"+word+"%")) | tmps.append(name+" LIKE "+sql_quote("%"+word+"%")) |
| tmp=string.join(tmps,' AND ') | tmp=string.join(tmps,' AND ') |
| Line 644 class ZSQLExtendFolder(Folder,Persistent | Line 652 class ZSQLExtendFolder(Folder,Persistent |
| ## op="ct" | ## op="ct" |
| ## name="LOWER("+name+")" | ## name="LOWER("+name+")" |
| ## if op=="ct": | ## if op=="ct": |
| ## whereList.append(name+" LIKE "+libpq.PgQuoteString("%"+value+"%")) | ## whereList.append(name+" LIKE "+sql_quote("%"+value+"%")) |
| ## elif op=="gt": | ## elif op=="gt": |
| ## whereList.append(name+">"+libpq.PgQuoteString(value)) | ## whereList.append(name+">"+sql_quote(value)) |
| ## elif op=="lt": | ## elif op=="lt": |
| ## whereList.append(name+"<"+libpq.PgQuoteString(value)) | ## whereList.append(name+"<"+sql_quote(value)) |
| ## elif op=="eq": | ## elif op=="eq": |
| ## whereList.append(name+"="+libpq.PgQuoteString(value)) | ## whereList.append(name+"="+sql_quote(value)) |
| ## elif op=="bw": | ## elif op=="bw": |
| ## whereList.append(name+" LIKE "+libpq.PgQuoteString(value+"%")) | ## whereList.append(name+" LIKE "+sql_quote(value+"%")) |
| ## elif op=="ew": | ## elif op=="ew": |
| ## whereList.append(name+" LIKE "+libpq.PgQuoteString("%"+value)) | ## whereList.append(name+" LIKE "+sql_quote("%"+value)) |
| ## op="ct" | ## op="ct" |
| ## #except: | ## #except: |
| Line 1119 class ZSQLBibliography(Folder,ZSQLExtend | Line 1127 class ZSQLBibliography(Folder,ZSQLExtend |
| def getMetaDatasXML(self): | def getMetaDatasXML(self): |
| """index""" | """index""" |
| # check if the request's host part was OK | |
| http_host = self.REQUEST['HTTP_HOST'] | |
| host_port = self.REQUEST['SERVER_PORT'] | |
| fix_host = None | |
| if http_host and http_host.rfind(host_port) == -1: | |
| print "HTTP_HOST needs fixing!" | |
| fix_host = http_host + ":" + host_port | |
| ret="""<?xml version="1.0" ?> | ret="""<?xml version="1.0" ?> |
| <index>""" | <index>""" |
| for found in self.ZSQLSimpleSearch("select oid from %s limit ALL"%self.tableName): | for found in self.ZSQLSimpleSearch("select oid from %s limit ALL"%self.tableName): |
| link=self.absolute_url()+"/"+"record.html?oid=%i"%found.oid | base_url = self.absolute_url() |
| metalink=self.absolute_url()+"/"+"getMetaDataXML?oid=%i"%found.oid | if fix_host: |
| #print "replacing ", http_host, " by ", fix_host | |
| base_url = string.replace(base_url, http_host, fix_host, 1) | |
| link=base_url+"/"+"record.html?oid=%i"%found.oid | |
| metalink=base_url+"/"+"getMetaDataXML?oid=%i"%found.oid | |
| ret+="""<resource resourceLink="%s" metaLink="%s"/>\n"""%(link,metalink) | ret+="""<resource resourceLink="%s" metaLink="%s"/>\n"""%(link,metalink) |