MCPcopy
hub / github.com/skywind3000/ECDICT / update

Method update

stardict.py:577–607  ·  view source on GitHub ↗
(self, key, items, commit = True)

Source from the content-addressed store, hash-verified

575
576 # 更新单词数据
577 def update (self, key, items, commit = True):
578 names = []
579 values = []
580 for name, id in self.__enable:
581 if name in items:
582 names.append(name)
583 value = items[name]
584 if name == 'detail':
585 if value is not None:
586 value = json.dumps(value, ensure_ascii = False)
587 values.append(value)
588 if len(names) == 0:
589 if commit:
590 try:
591 self.__conn.commit()
592 except MySQLdb.Error as e:
593 self.out(str(e))
594 return False
595 return False
596 sql = 'UPDATE stardict SET ' + ', '.join(['%s=%%s'%n for n in names])
597 if isinstance(key, str) or isinstance(key, unicode):
598 sql += ' WHERE word=%s;'
599 else:
600 sql += ' WHERE id=%s;'
601 try:
602 with self.__conn as c:
603 c.execute(sql, tuple(values + [key]))
604 except MySQLdb.Error as e:
605 self.out(str(e))
606 return False
607 return True
608
609 # 取得数据量
610 def count (self):

Callers 1

registerMethod · 0.95

Calls 3

outMethod · 0.95
dumpsMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected