def insertSomeData(self, tableName, field1, field2, word1, word2): tables = self.showTables() if (tables is None): self.createOneColTable(tableName) else: if (ms.inEqual(tableName, tables)): pass else: self.createOneColTable(tableName) col = self.getColName(tableName) if (ms.inEqual(field1, col)): pass else: self.addColTable(tableName, field1, 34) col = self.getColName(tableName) data = self.selectFieldData(tableName, 'word') if (data is None or (not ms.inEqual(word1, data))): self.insertTwoDataOnly(tableName, field2, word1, word2) else: self.updateParticularDataByAdding(tableName, field1, field2, word1, word2)
def insertInIdentity(self, word, identity): tables = self.showTables() oddTables = ms.oddOut(tables, identity) #Table creation if not present if (len(oddTables) == 0): pass else: for i in oddTables: field = ['word'] size = [100] self.createTable(i, field, size) for i in identity: data = self.selectAllData(i) if (data == None): sqlFormula = 'insert into ' + i + ' values("' + word + '")' self.mycursor.execute(sqlFormula) else: if (ms.inEqual(word, data)): pass else: sqlFormula = 'insert into ' + i + ' values("' + word + '")' self.mycursor.execute(sqlFormula)
def insertInAlfa(self, word, identity): tableName = word[0] cols = self.getColName(tableName) data = self.selectAllData(tableName) dic = {} if data == None: newIdentity = ms.mergeString(identity, '/') sqlFormula = 'insert into ' + tableName + ' values("' + word + '","' + newIdentity + '")' self.mycursor.execute(sqlFormula) else: d1 = [] for i in data: dic.__setitem__(i[0].lower(), i[1].lower()) d1.append(i[0].lower()) if (ms.inEqual(word, d1)): ident = dic[word] dis = ms.distributeString(ident, '/') nident = ms.sortOut(dis, identity) newmid = ms.mergeString(nident, '/') self.updateParticularData(tableName, cols[0], cols[1], word, newmid) else: newIdentity = ms.mergeString(identity, '/') sqlFormula = 'insert into ' + tableName + ' values("' + word + '","' + newIdentity + '")' self.mycursor.execute(sqlFormula)
def checkTable(self, tableName): table = self.showTables() if (table is None or (not ms.inEqual(tableName, table))): return False else: return True
def createTableTextSize(self, tableName, fields): length = len(fields) tables = self.showTables() if (tables is None): string = '' for i in range(0, length): string = string + fields[i] + ' longtext ,' string = string[:-1] sqlFormula = sqlFormula = 'create table ' + tableName + '(' + string + ')' #print(sqlFormula) self.mycursor.execute(sqlFormula) return True else: if (ms.inEqual(tableName, tables)): return False else: string = '' for i in range(0, length): string = string + fields[i] + ' longtext ,' string = string[:-1] sqlFormula = 'create table ' + tableName + '(' + string + ')' #print(sqlFormula) self.mycursor.execute(sqlFormula) return True
def inMultipleEqual(array1, array2): con = False for i in array1: if (ms.inEqual(i, array2)): con = True break return con
def checkArrayEquality(array1, array2): val = False for i in array1: con = ms.inEqual(i, array2) if (con): val = True break return val
def commonAllOut(array1, array2): val = [] for i in array1: if (ms.inEqual(i, array2)): val.append(i) if (len(val) == 0): return None else: return val
def createOneColTable(self, tableName): tables = self.showTables() field = ['word'] size = [100] if (tables is None): self.createTable(tableName, field, size) else: if (ms.inEqual(tableName, tables)): pass else: self.createTable(tableName, field, size)
def checkingWords(self, words): for i in words: first = i[0] data = self.selectAllData(first) #print(data,i) if (data == None): print('hii') return False elif (ms.inEqual(i, data)): return True else: return False
def getColName(self, tableName): sqlFormula = 'desc ' + tableName table = self.showTables() if (table is None or (not ms.inEqual(tableName, table))): return None else: self.mycursor.execute(sqlFormula) res = self.mycursor.fetchall() field = [] for i in res: field.append(i[0]) return field
def insertTwoInOne(self, word1, identity1, word2, identity2): tables = ms.makePair(identity1, identity2) dtable = self.showTables() outTables = ms.oddOut(dtable, tables) #Table is created if (len(outTables) == 0): pass else: for i in outTables: fields = ['word1', 'word2'] size = [100, 100] self.createTable(i, fields, size) for i in tables: data = self.selectAllData(i) if (data == None): sqlFormula = 'insert into ' + i + ' values ("' + word1 + '","' + word2 + '")' self.mycursor.execute(sqlFormula) else: dic = ms.makeDictionary(data) d1 = [] for ni in data: d1.append(ni[0]) if (ms.inEqual(word1, d1)): wo = dic[word1] if (ms.equalWord(wo, word2, trim=True)): pass else: sqlFormula = 'insert into ' + i + ' values ("' + word1 + '","' + word2 + '")' self.mycursor.execute(sqlFormula) else: sqlFormula = 'insert into ' + i + ' values ("' + word1 + '","' + word2 + '")' self.mycursor.execute(sqlFormula)