def init_database(): bank_exist = engine.check_table_exist("t_bank") init_result = [False, False] config_exist = engine.check_table_exist("t_config") if not config_exist: config_sql = """create table t_config( pno INTEGER primary key autoincrement, left_top VARCHAR, right_bottom VARCHAR, auto_apply INTEGER, left_top_ans VARCHAR, right_bottom_ans VARCHAR, ans_1 VARCHAR, ans_2 VARCHAR, ans_3 VARCHAR, ans_4 VARCHAR )""" engine.execute(query=config_sql) init_result[0] = True if not bank_exist: sql = """create table t_bank( pno INTEGER primary key autoincrement, ques VARCHAR not null, ans VARCHAR, wrong_ans VARCHAR )""" engine.execute(query=sql) init_result[1] = True return init_result
def search_related_records(word_list): params = "%" if len(word_list) <= 1: return [] for word in word_list: params += word[:3] params += "%" # print(params) sql = "select * from t_bank where ques like '{}'".format(params) res = engine.execute(query=sql).fetchall() # print(res) return res
def init_data(ques, ans, wrong_ans=""): sql = "insert into t_bank(ques, ans, wrong_ans) values (\"{}\", \"{}\", \"{}\")".format( ques, ans, wrong_ans) engine.execute(query=sql)
def init_config(): sql = "insert into t_config(auto_apply) values (\"{}\")".format(1) engine.execute(query=sql)
def get_user_config(): config_exist = engine.check_table_exist("t_config") if config_exist: config_exist = config = engine.execute( query="select * from t_config limit 1").fetchone() return config_exist