def setUp(self): GameUtil.flush_cache() self.cur = DB.cursor() self.cur.execute("DELETE FROM account") self.cur.execute("DELETE FROM account_actor") self.cur.execute("DELETE FROM actor") self.cur.execute("DELETE FROM actor_message") self.cur.execute("DELETE FROM actor_properties") self.cur.execute("DELETE FROM item") self.cur.execute("DELETE FROM item_owner") self.cur.execute("DELETE FROM item_properties") self.cur.execute("DELETE FROM location") self.cur.execute("DELETE FROM location_properties") self.cur.execute("DELETE FROM log_raw_action") DB.commit()
def insert_to_database(self): cursor = DB.cursor() query = "INSERT INTO products (id, name, subname, price, score)\ VALUES(%s, %s, %s, %s, %s)" values = (self.id, self.name, self.subname, self.price, self.score) try: cursor.execute(query, values) except mysql.connector.errors.DataError: pass except mysql.connector.errors.IntegrityError: pass self.opinions.insert_to_database() DB.commit()
def insert_to_database(self): cursor = DB.cursor() query = "INSERT INTO opinions (\ id, product_id, author, recommendation, stars, content,\ useful, useless, purchased, review_date, purchase_date\ )\ VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" values = (self.id, self.product_id, self.author, self.recommendation, self.stars, self.content, self.useful, self.useless, self.purchased, self.review_date, self.purchase_date) try: cursor.execute(query, values) except mysql.connector.errors.DataError: pass except mysql.connector.errors.IntegrityError: pass if self.pros is not None: for pro in self.pros.strip().split("\n"): query = "INSERT INTO pros (opinion_id, text) VALUES( %s, %s)" values = (self.id, pro) try: cursor.execute(query, values) print("s") except mysql.connector.errors.DataError: pass except mysql.connector.errors.IntegrityError: pass if self.cons is not None: for con in self.cons.strip().split("\n"): query = "INSERT INTO cons (opinion_id, text) VALUES( %s, %s)" values = (self.id, con) try: cursor.execute(query, values) except mysql.connector.errors.DataError: pass except mysql.connector.errors.IntegrityError: pass DB.commit()