def updatetableinfo_byparams(self,table,select_params=[],set_params=[],request_params=[],equal_params=[],extra=''): if len(request_params)!=len(equal_params): print 'request_params,equals_params长度不相等' return False elif self.__isconnect==1: try: sql='update ' length=len(table) for j in range(0,length-1): sql=sql+table[j]+',' sql=sql+table[length-1] select_params_length=len(select_params) if select_params_length>0: sql=sql+' set ' for k in range(0,select_params_length-1): sql=sql+select_params[k]+' = '+set_params[k]+' , ' sql=sql+select_params[select_params_length-1]+' = '+set_params[select_params_length-1]+' ' request_params_length=len(request_params) if request_params_length>0: sql=sql+' where ' for k in range(0,request_params_length-1): sql=sql+request_params[k]+' = '+equal_params[k]+' and ' sql=sql+request_params[request_params_length-1]+' = '+equal_params[request_params_length-1]+' ' sql+=extra # print sql count=None try: count=self.__cur.execute(sql) self.__conn.commit() except MySQLdb.Error,e: try: if self.isdisconnect(e): self.connectdb() count=self.__cur.execute(sql) self.__conn.commit() else: debug=Debug.getObject() debug.error(str(e)) return False except Exception,e: return False if count>0: return True else: return False
def inserttableinfo_byparams(self, table, select_params, insert_values, extra=' ', updatevalue=[]): if len(insert_values) < 1: print '没有插入参数' return False elif self.__isconnect == 1: try: sql = 'insert into ' + table length = len(select_params) if length > 0: sql += '(' for j in range(0, length - 1): sql = sql + select_params[j] + ',' sql = sql + select_params[length - 1] + ')' sql = sql + ' ' sql = sql + ' values(' for j in range(0, length - 1): sql = sql + '%s' + ',' sql = sql + '%s' + ')' else: return False ulen = len(updatevalue) if ulen > 0: sql += ' on duplicate key update ' for o in range(0, ulen - 1): sql = sql + updatevalue[o] + ' = %s ' + ' ,' sql = sql + updatevalue[ulen - 1] + ' =%s ' sql += extra print sql print insert_values returnmeg = None try: returnmeg = self.__cur.executemany(sql, insert_values) except MySQLdb.Error, e: try: if self.isdisconnect(e): self.connectdb() returnmeg = self.__cur.executemany( sql, insert_values) else: debug = Debug.getObject() debug.error(str(e)) return False except Exception, e: return False print '返回的消息: ' + str(returnmeg) if returnmeg > 0: if self.__conn is not None: self.__conn.commit() return True else: return False
def replaceinserttableinfo_byparams(self, table, select_params, insert_values): if len(insert_values) < 1: print '没有插入参数' return False elif self.__isconnect == 1: try: sql = 'replace into ' + table length = len(select_params) if length > 0: sql += '(' for j in range(0, length - 1): sql = sql + select_params[j] + ',' sql = sql + select_params[length - 1] + ')' sql = sql + ' ' sql = sql + ' values(' for j in range(0, length - 1): sql = sql + '%s' + ',' sql = sql + '%s' + ')' else: return False # print sql returnmeg = None try: returnmeg = self.__cur.executemany(sql, insert_values) print '返回的消息: ' + str(returnmeg) self.__conn.commit() if str(returnmeg) == '0': print '没有数据变化' return True # self.connectdb() # returnmeg=self.__cur.executemany(sql,insert_values) # print '返回的消息: '+str(returnmeg) # self.__conn.commit() except MySQLdb.Error, e: try: if self.isdisconnect(e): print '进行重连' self.connectdb() returnmeg = self.__cur.executemany( sql, insert_values) print '返回的消息: ' + str(returnmeg) self.__conn.commit() return True else: debug = Debug.getObject() debug.error(str(e)) return False except Exception, e: return False
def replaceinserttableinfo_byparams(self,table,select_params,insert_values): if len(insert_values)<1 : print '没有插入参数' return False elif self.__isconnect==1: try: sql='replace into '+table length=len(select_params) if length > 0: sql+='(' for j in range(0,length-1): sql=sql+select_params[j]+',' sql=sql+select_params[length-1]+')' sql=sql+' ' sql=sql+' values(' for j in range(0,length-1): sql=sql+'%s'+',' sql=sql+'%s'+')' else: return False # print sql returnmeg=None try: returnmeg=self.__cur.executemany(sql,insert_values) print '返回的消息: '+str(returnmeg) self.__conn.commit() if str(returnmeg)=='0': print '没有数据变化' return True # self.connectdb() # returnmeg=self.__cur.executemany(sql,insert_values) # print '返回的消息: '+str(returnmeg) # self.__conn.commit() except MySQLdb.Error,e: try: if self.isdisconnect(e): print '进行重连' self.connectdb() returnmeg=self.__cur.executemany(sql,insert_values) print '返回的消息: '+str(returnmeg) self.__conn.commit() return True else: debug=Debug.getObject() debug.error(str(e)) return False except Exception,e: return False
def inserttableinfo_byparams(self,table,select_params,insert_values,extra=' ',updatevalue=[]): if len(insert_values)<1 : print '没有插入参数' return False elif self.__isconnect==1: try: sql='insert into '+table length=len(select_params) if length > 0: sql+='(' for j in range(0,length-1): sql=sql+select_params[j]+',' sql=sql+select_params[length-1]+')' sql=sql+' ' sql=sql+' values(' for j in range(0,length-1): sql=sql+'%s'+',' sql=sql+'%s'+')' else: return False ulen=len(updatevalue) if ulen>0: sql+=' on duplicate key update ' for o in range(0, ulen-1): sql=sql+updatevalue[o]+' = %s '+' ,' sql=sql+updatevalue[ulen-1]+' =%s ' sql+=extra # print sql returnmeg=None try: returnmeg=self.__cur.executemany(sql,insert_values) except MySQLdb.Error,e: try: if self.isdisconnect(e): self.connectdb() returnmeg=self.__cur.executemany(sql,insert_values) else: debug=Debug.getObject() debug.error(str(e)) return False except Exception,e: return False print '返回的消息: '+str(returnmeg) if returnmeg>0: if self.__conn is not None: self.__conn.commit() return True else: return False
def searchtableinfo_byparams(self,table,select_params=[],request_params=[],equal_params=[],limit='',order='',extra='',command='and'): if len(request_params)!=len(equal_params): print 'request_params,equals_params长度不相等' return (0,0,0,0) elif self.__isconnect==1: try: sql='select ' length=len(select_params) if length > 0: for j in range(0,length-1): sql=sql+select_params[j]+',' sql=sql+select_params[length-1] else: sql=sql+'*' sql=sql+' from ' length=len(table) for j in range(0,length-1): sql=sql+table[j]+',' sql=sql+table[length-1] request_params_length=len(request_params) if request_params_length>0: sql=sql+' where ' for k in range(0,request_params_length-1): sql=sql+request_params[k]+' = '+equal_params[k]+' '+command+' ' sql=sql+request_params[request_params_length-1]+' = '+equal_params[request_params_length-1]+' ' sql+=extra if order!='': sql+=' order by '+order sql+=limit sql+='' # print sql count=None try: if self.__cur is not None: count=self.__cur.execute(sql) else: self.connectdb() count=self.__cur.execute(sql) except MySQLdb.Error,e: try: if self.isdisconnect(e): self.connectdb() count=self.__cur.execute(sql) else: debug=Debug.getObject() debug.error(str(e)) return (0,0,0,0) except Exception,e: return (0,0,0,0) if count>0: result=self.__cur.fetchall() content=self.__cur.description """ print '相关信息如下:' print result print content for temp in content: print temp[0], print '' for temp in result: for i in range(0,len(temp)): print temp[i], print '' """ col=None if content is not None: col= len(content) return result,content,count,col else: print '没有相关信息' return (0,0,0,0)
def updatetableinfo_byparams(self, table, select_params=[], set_params=[], request_params=[], equal_params=[], extra=''): if len(request_params) != len(equal_params): print 'request_params,equals_params长度不相等' return False elif self.__isconnect == 1: try: sql = 'update ' length = len(table) for j in range(0, length - 1): sql = sql + table[j] + ',' sql = sql + table[length - 1] select_params_length = len(select_params) if select_params_length > 0: sql = sql + ' set ' for k in range(0, select_params_length - 1): sql = sql + select_params[k] + ' = ' + set_params[ k] + ' , ' sql = sql + select_params[select_params_length - 1] + ' = ' + set_params[ select_params_length - 1] + ' ' request_params_length = len(request_params) if request_params_length > 0: sql = sql + ' where ' for k in range(0, request_params_length - 1): sql = sql + request_params[k] + ' = ' + equal_params[ k] + ' and ' sql = sql + request_params[request_params_length - 1] + ' = ' + equal_params[ request_params_length - 1] + ' ' sql += extra # print sql count = None try: count = self.__cur.execute(sql) self.__conn.commit() except MySQLdb.Error, e: try: if self.isdisconnect(e): self.connectdb() count = self.__cur.execute(sql) self.__conn.commit() else: debug = Debug.getObject() debug.error(str(e)) return False except Exception, e: return False if count > 0: return True else: return False
def searchtableinfo_byparams(self, table, select_params=[], request_params=[], equal_params=[], limit='', order='', extra='', command='and'): if len(request_params) != len(equal_params): print 'request_params,equals_params长度不相等' return (0, 0, 0, 0) elif self.__isconnect == 1: try: sql = 'select ' length = len(select_params) if length > 0: for j in range(0, length - 1): sql = sql + select_params[j] + ',' sql = sql + select_params[length - 1] else: sql = sql + '*' sql = sql + ' from ' length = len(table) for j in range(0, length - 1): sql = sql + table[j] + ',' sql = sql + table[length - 1] request_params_length = len(request_params) if request_params_length > 0: sql = sql + ' where ' for k in range(0, request_params_length - 1): sql = sql + request_params[k] + ' = ' + equal_params[ k] + ' ' + command + ' ' sql = sql + request_params[request_params_length - 1] + ' = ' + equal_params[ request_params_length - 1] + ' ' sql += extra if order != '': sql += ' order by ' + order sql += limit sql += '' print sql count = None try: if self.__cur is not None: count = self.__cur.execute(sql) else: self.connectdb() count = self.__cur.execute(sql) except MySQLdb.Error, e: try: if self.isdisconnect(e): self.connectdb() count = self.__cur.execute(sql) else: debug = Debug.getObject() debug.error(str(e)) return (0, 0, 0, 0) except Exception, e: return (0, 0, 0, 0) if count > 0: result = self.__cur.fetchall() content = self.__cur.description """ print '相关信息如下:' print result print content for temp in content: print temp[0], print '' for temp in result: for i in range(0,len(temp)): print temp[i], print '' """ col = None if content is not None: col = len(content) return result, content, count, col else: print '没有相关信息' return (0, 0, 0, 0)
def __init__(self): self.oo = 1 def temp(self, name): print name def fuc(self): print '123' def ad(self): return 1 v = alotod() print v.temp.__name__ # k=getattr(v, 'ad','1')() try: try: pp = 1 pp[2] = '' except Exception, e: print 2222 except Exception, e: print 12222 e = 'askjdajksnd Masdnk' if 'M' in str(e): print 123123 debug = Debug.getObject() debug.error("asd")
print arg4 kwargs = {"arg3": 3, "arg2": "two","arg1":p} # dictionary fun_var_args_call(**kwargs) class alotod: def __init__(self): self.oo=1 def temp(self,name): print name def fuc(self): print '123' def ad(self): return 1 v=alotod() print v.temp.__name__ # k=getattr(v, 'ad','1')() try: try: pp=1 pp[2]='' except Exception,e: print 2222 except Exception,e: print 12222 e='askjdajksnd Masdnk' if 'M' in str(e): print 123123 debug=Debug.getObject() debug.error("asd")