def selectSomeField(self, tableName, fields, values): temp = [] for i in range(0, len(values)): fi = fields[i] val = values[i] d = fi + '="' + val + '"' temp.append(d) temp = ms.mergeInString(temp, ' and ') sqlFormula = 'select * from {1} where {2}'.format(tableName, temp) self.mycursor.execute(sqlFormula) res = self.mycursor.fetchall() return res
def selectByMulAndCond(self, tableName, fields, words, part='*'): values = [] for i in range(0, len(fields)): d = fields[i] + '="' + words[i] + '" ' values.append(d) values = ms.mergeInString(values, ' and ') sqlFormula = 'select ' + part + ' from {0} where {1}'.format( tableName, values) self.mycursor.execute(sqlFormula) res = self.mycursor.fetchall() return res
def countByCond(self, tableName, fields, values): sen = [] for i in range(0, len(fields)): sen.append(fields[i] + '="' + values[i] + '"') sen = ms.mergeInString(sen, ' and ') sqlFormula = 'select count(*) from {0} where {1}'.format( tableName, sen) self.mycursor.execute(sqlFormula) res = self.mycursor.fetchall() data = ms.modifySqlResult(res) return data[0]
def deleteByMulOrCon(self, tableName, fields, values): if (len(fields) == len(values)): con = [] for i in range(0, len(fields)): field = fields[i] value = values[i] co = field + '="' + value + '"' con.append(co) condition = ms.mergeInString(con, ' or ') sqlFormula = 'delete from {0} where {1}'.format( tableName, condition) self.mycursor.execute(sqlFormula) else: print('error : values length are not same')
def checkDataCond(self, tableName, fields, words): sen = [] for i in range(0, len(fields)): d = fields[i] + '="' + words[i] + '"' sen.append(d) sen = ms.mergeInString(sen, ' and ') sqlFormula = 'select * from {0} where {1}'.format(tableName, sen) self.mycursor.execute(sqlFormula) res = self.mycursor.fetchall() if (res is None or len(res) == 0): return False else: return True
def checkMulOrData(self, tableName, fields, words): aftw = [] for i in range(0, len(fields)): field = fields[i] word = words[i] d = field + '="' + word + '" ' aftw.append(d) aftw = ms.mergeInString(aftw, 'or ') sqlFormula = 'select * from {0} where {1}'.format(tableName, aftw) self.mycursor.execute(sqlFormula) res = self.mycursor.fetchall() if (res is None or len(res) == 0): return False else: return True
def replaceBy_String(string, word, agent='_'): dis = ms.distributeString(string, word) data = ms.mergeInString(dis, agent) return data