--- ZSQLExtend/ZSQLExtend.py 2005/11/08 13:37:32 1.71 +++ ZSQLExtend/ZSQLExtend.py 2005/12/22 21:10:34 1.77 @@ -67,6 +67,11 @@ class ZSQLExtendFolder(Folder,Persistent """Folder""" meta_type="ZSQLExtendFolder" + def ZSQLQuote(self,str): + """quote str for sql""" + return sql_quote(str) + + def importXMLFile(self,table,containerTagName,file,identify=None,RESPONSE=None): #TODO: finish importXMLFile ''' @@ -98,7 +103,7 @@ class ZSQLExtendFolder(Folder,Persistent """erzeuge index aus feld""" index={} founds=self.ZSQLSimpleSearch("""SELECT %s,oid FROM %s LIMIT 2000"""%(field,table)) - print len(founds) + for found in founds: tmp=getattr(found,field,None) if tmp: @@ -202,6 +207,8 @@ class ZSQLExtendFolder(Folder,Persistent def formatAscii(self,str,url=None): """ersetze ascii umbrueche durch
""" #url=None + str=str.rstrip().lstrip() + if url and str: retStr="" @@ -234,22 +241,22 @@ class ZSQLExtendFolder(Folder,Persistent return "" def actualPath(self,url=None): - """path""" + """path""" if self.REQUEST['HTTP_X_FORWARDED_SERVER']=='': host=self.REQUEST['HTTP_HOST'] else: host=self.REQUEST['HTTP_X_FORWARDED_SERVER'] - if not url: - return "http://"+host+self.REQUEST['PATH_TRANSLATED'] - else: - temp=self.REQUEST[url].split("/") - temp[2]=host - return string.join(temp,"/") + if not url: + return "http://"+host+self.REQUEST['PATH_TRANSLATED'] + else: + temp=self.REQUEST[url].split("/") + temp[2]=host + return string.join(temp,"/") def getRequest(self): - """request""" - return self.REQUEST + """request""" + return self.REQUEST def lowerEnd(self,path): """oinly for demo""" @@ -266,12 +273,12 @@ class ZSQLExtendFolder(Folder,Persistent def ZSQLsearchOptions(self,fieldname=""): """return HTML Fragment with search options""" - + ret=""""""%fieldname return ret @@ -313,8 +320,8 @@ class ZSQLExtendFolder(Folder,Persistent ret=""" """%(fieldname,multiple,additionalSelect) if start: - if start==' ': - start='' - if not startValue: + if start==' ': + start='' + + if not startValue: startValue=start - + ret+=""""""%(startValue,start) for result in results: field=getattr(result,fieldName) @@ -377,6 +385,7 @@ class ZSQLExtendFolder(Folder,Persistent qs=[] if storename: """store""" + storename=storename else: storename="foundCount" @@ -422,12 +431,24 @@ class ZSQLExtendFolder(Folder,Persistent #print "INLINE:",query return self.ZSQLSimpleSearch(query) - + + def ZSQLResetConnection(self): + """reset the connectione""" + try: + self.getConnectionObj().manage_close_connection() + except: + zLOG.LOG("ZSQLResetConnection",zLOG.ERROR, '%s %s'%sys.exc_info()[:2]) + try: + self.getConnectionObj().manage_open_connection() + except: + zLOG.LOG("ZSQLResetConnection",zLOG.ERROR, '%s %s'%sys.exc_info()[:2]) + def ZSQLSimpleSearch(self,query=None,max_rows=1000000): """simple search""" - + if not query: query=self.query + if (hasattr(self,"_v_searchSQL") and (self._v_searchSQL == None)) or (not hasattr(self,"_v_searchSQL")): @@ -435,9 +456,9 @@ class ZSQLExtendFolder(Folder,Persistent self._v_searchSQL.max_rows_=max_rows try: - return self._v_searchSQL.__call__(var=query) except : + if sys.exc_info()[0]=="Database Error": try: self.getConnectionObj().manage_open_connection() @@ -445,10 +466,12 @@ class ZSQLExtendFolder(Folder,Persistent zLOG.LOG("ZSQLSimpleSearch",zLOG.ERROR, '%s %s'%sys.exc_info()[:2]) else: try: + self._v_searchSQL.max_rows_=max_rows return self._v_searchSQL.__call__(var=query) except : + if sys.exc_info()[0]=="Database Error": try: self.getConnectionObj().manage_open_connection() @@ -575,11 +598,13 @@ class ZSQLExtendFolder(Folder,Persistent elif name=="-format": format=urllib.unquote(value) elif (not (name[0]=="-" or name[0]=="_")) and (not len(value)==0): + changeList.append("\""+name+"\"="+sql_quote(urllib.unquote(value))) changeString=string.join(changeList,",") + queryString="UPDATE %s SET %s WHERE %s"%(table,changeString,identify) - + self.ZSQLSimpleSearch(queryString) @@ -812,7 +837,7 @@ class ZSQLExtendFolder(Folder,Persistent #check for op splitted=qs.split(",") - print splitted + if tableExt: table=tableExt @@ -914,7 +939,7 @@ class ZSQLExtendFolder(Folder,Persistent op="ct" namealt=name name="LOWER("+punktsplit[1]+")" - print "XX",op + if op=="ct": tmp=(name+" LIKE "+sql_quote("%"+value+"%")) elif op=="gt": @@ -948,9 +973,9 @@ class ZSQLExtendFolder(Folder,Persistent op="all" - print punktsplit + searchTmp="""%s in (select %s from %s where %s)"""%(punktsplit[3],punktsplit[2],punktsplit[0],tmp) - print "got",searchTmp + queryTemplate.append(searchTmp) elif (not name[0]==iCT) and (not len(value)==0): @@ -1031,13 +1056,14 @@ class ZSQLExtendFolder(Folder,Persistent #print "QE",table #print (select,table,where,sort,maxstr,skip) query="SELECT %s FROM %s %s %s %s %s"%(select,table,where,sort,maxstr,skip) - print query + if not nostore=="yes": self.REQUEST.SESSION['qs']=opfields #print "IAMHERE again:", query if storename and (not NoQuery): + query2="SELECT count(*) FROM %s %s"%(table,where) #print "QUERYSTRING:",self.REQUEST.SESSION[storename]['queryString2'] @@ -1562,7 +1588,7 @@ class ZSQLBibliography(Folder,ZSQLExtend host_port = self.REQUEST['SERVER_PORT'] fix_host = None if http_host and http_host.rfind(host_port) == -1: - print "HTTP_HOST needs fixing!" + #print "HTTP_HOST needs fixing!" fix_host = http_host + ":" + host_port ret="""