def sort(cls, new_order): cur = get_db().cursor() for e in new_order: cur.execute("UPDATE %s SET '%s' = ? WHERE id = ?" % (cls.__table_name__, "order"), (e[1], e[0])) get_db().commit()
def get_max_order(cls, id): cur = get_db().cursor() cur.execute( "SELECT max(fermenter_step.'order') as 'order' FROM %s WHERE fermenter_id = ?" % cls.__table_name__, (id, )) r = cur.fetchone() return r.get("order")
def get_by_fermenter_id(cls, id): cur = get_db().cursor() cur.execute("SELECT * FROM %s WHERE fermenter_id = ?" % cls.__table_name__,(id,)) result = [] for r in cur.fetchall(): result.append(cls(r)) return result
def get_by_state(cls, state, order=True): cur = get_db().cursor() cur.execute("SELECT * FROM %s WHERE state = ? ORDER BY %s.'order'" % (cls.__table_name__,cls.__table_name__,), state) r = cur.fetchone() if r is not None: return cls(r) else: return None
def get_by_state(cls, state): cur = get_db().cursor() cur.execute("SELECT * FROM %s WHERE state = ?" % cls.__table_name__, state) r = cur.fetchone() if r is not None: return cls(r) else: return None
def reset_all_steps(cls, id): cur = get_db().cursor() cur.execute( "UPDATE %s SET state = 'I', start = NULL, end = NULL, timer_start = NULL WHERE fermenter_id = ?" % cls.__table_name__, (id, )) get_db().commit()
def update_timer(cls, id, timer): cur = get_db().cursor() cur.execute( "UPDATE %s SET timer_start = ? WHERE id =?" % cls.__table_name__, (timer, id)) get_db().commit()
def update_state(cls, id, state): cur = get_db().cursor() cur.execute("UPDATE %s SET state = ? WHERE id =?" % cls.__table_name__, (state, id)) get_db().commit()
def reset_all_steps(cls): cur = get_db().cursor() cur.execute("UPDATE %s SET state = 'I', stepstate = NULL , start = NULL, end = NULL " % cls.__table_name__) get_db().commit()
def delete_all(cls): cur = get_db().cursor() cur.execute("DELETE FROM %s" % cls.__table_name__) get_db().commit()
def get_max_order(cls): cur = get_db().cursor() cur.execute("SELECT max(step.'order') as 'order' FROM %s" % cls.__table_name__) r = cur.fetchone() return r.get("order")