def zh2en(ctx, word): word = word.lower() path = os.path.join(xconfig.DATA_PATH, "dictionary.db") if not os.path.exists(path): return [] sql = "SELECT * FROM dictTB WHERE cn LIKE ?" dicts = xutils.db_execute(path, sql, ('%' + word, )) if len(dicts) > 0: return wrap_results(dicts, "cn") sql = "SELECT * FROM dictTB WHERE cn LIKE ?" dicts = xutils.db_execute(path, sql, ('%' + word + '%', )) return wrap_results(dicts, "cn")
def zh2en(word): word = word.lower() path = os.path.join(xconfig.DATA_PATH, "dictionary.db") if not os.path.exists(path): return [] sql = "SELECT * FROM dictTB WHERE cn LIKE ?" dicts = xutils.db_execute(path, sql, ('%' + word, )) if len(dicts) > 0: return wrap_results(dicts, "cn") sql = "SELECT * FROM dictTB WHERE cn LIKE ?" dicts = xutils.db_execute(path, sql, ('%' + word + '%', )) return wrap_results(dicts, "cn") # xmanager.register_search_func(r"(.*)", find_translate)
def search(word): """英汉翻译""" word = word.lower() path = os.path.join(xconfig.DATA_PATH, "dictionary.db") if not os.path.exists(path): return [] sql = "SELECT * FROM dictTB WHERE LOWER(en)=?" dicts = xutils.db_execute(path, sql, (word, )) return wrap_results(dicts, "en")
def search(ctx, word): """英汉翻译""" word = word.lower() path = os.path.join(xconfig.DATA_PATH, "dictionary.db") if not os.path.exists(path): return [] # COLLATE NOCASE是sqlite的方言 # 比较通用的做法是冗余字段 sql = "SELECT * FROM dictTB WHERE en=? COLLATE NOCASE" dicts = xutils.db_execute(path, sql, (word, )) return wrap_results(dicts, "en")
def execute(self, sql, args=None): # 不建议使用,尽量使用query return xutils.db_execute(self.dbpath, sql, args)