def get_all_data(self): sql = ''' SELECT * FROM urls ''' db = SqliteCon() data = db.fetchall(sql) return data
def init_db(self): sql = """CREATE TABLE IF NOT EXISTS 'urls' ( 'id' INTEGER PRIMARY KEY AUTOINCREMENT, 'url' TEXT, 'status' INTEGER, 'status_label' TEXT, 'is_checked' INTEGER )""" db = SqliteCon() db.execute(sql)
def search(self, to_search, factor): sql = "SELECT * FROM urls " params = () if to_search != "": if factor.lower() == "url": sql = sql + "WHERE url LIKE ? " params = (to_search + '%', ) elif factor.lower() == "status": sql = sql + "WHERE status LIKE ? " params = (to_search + '%', ) else: sql = sql + "WHERE url LIKE ? OR status LIKE ? " params = (to_search + '%', to_search + '%') db = SqliteCon() return db.fetchall(sql, params)
def delete_url(self, url_id): sql = "DELETE FROM urls WHERE id = ?" params = (url_id, ) db = SqliteCon() db.delete(sql, params)
def get_checked_urls(self): sql = "SELECT * FROM urls WHERE is_checked = ?" params = (1, ) db = SqliteCon() return db.fetchall(sql, params)
def update_url(self, url_obj): sql = "UPDATE urls SET url = ?, is_checked = ?, status = ? , status_label = ? WHERE id = ?" params = (url_obj.url, url_obj.is_checked, url_obj.status.value, self.get_status_label(url_obj.status), url_obj.id) con = SqliteCon() con.update(sql, params)
def insert_url(self, url_obj): sql = "INSERT INTO urls(url, status, status_label, is_checked) VALUES(?, ?, ?, ?)" params = (url_obj.url, url_obj.status.value, self.get_status_label(url_obj.status), url_obj.is_checked) con = SqliteCon() return con.insert(sql, params)