示例#1
0
def create_tables():
    cur = db_iface.get_cursor()
    cur.execute(CREATE_TAB_TAG)
    cur.execute(CREATE_TAB_TAG_IN_MOM)
    cur.execute(SET_TAB_VERSION, (TAB_VERSION, ))
    db_iface.commit()
    cur.close()
示例#2
0
文件: mom.py 项目: stethewwolf/Sapy
    def update(self,
               new_value=None,
               new_cause=None,
               new_year=None,
               new_month=None,
               new_day=None):
        cur = db_iface.get_cursor()

        if new_value:
            cur.execute(UPDATE_MOM_VALUE, (
                new_value,
                self.id,
            ))

        if new_cause:
            cur.execute(UPDATE_MOM_TIME, (
                new_cause,
                self.id,
            ))

        if new_year and new_month and new_day:
            new_time = datetime.date(year=new_year,
                                     month=new_month,
                                     day=new_day)
            cur.execute(UPDATE_MOM_TIME, (
                new_time,
                self.id,
            ))

        db_iface.commit()
        cur.close()
示例#3
0
文件: mom.py 项目: stethewwolf/Sapy
    def __init__(self,
                 id: int = None,
                 value: float = 0,
                 cause: str = "not specified",
                 year: int = datetime.datetime.today().date().year,
                 month: int = datetime.datetime.today().date().month,
                 day: int = datetime.datetime.today().date().day):
        self.value = float(value)
        self.cause = cause  # description of money movement
        self.time = datetime.date(int(year), int(month), int(day))

        if id == None:
            cur = db_iface.get_cursor()
            cur.execute(INSERT_MOM, (
                self.value,
                self.cause,
                self.time,
            ))

            cur.execute(GET_LAST_MOM)
            self.id = cur.fetchone()[0]

            db_iface.commit()
            cur.close()
        else:
            self.id = id
示例#4
0
 def delete(self):
     cur = db_iface.get_cursor()
     cur.execute("delete from tags where id = ?", (self.id, ))
     cur.execute("delete from tag_in_mom where tag_id = ?", (self.id, ))
     db_iface.commit()
     cur.close()
     self.name = None
     self.id = None
示例#5
0
 def set_visible(self, value):
     self.visible = value
     cur = db_iface.get_cursor()
     if self.visible:
         cur.execute(UPDATE_LOM_VISIBLE, (1, self.id))
     else:
         cur.execute(UPDATE_LOM_VISIBLE, (0, self.id))
     db_iface.commit()
示例#6
0
def create_tables():
    cur = db_iface.get_cursor()
    cur.execute(CREATE_TABLE_LOM)
    cur.execute(CREATE_TABLE_MOM_IN_LOM)
    cur.execute(CREATE_DEFAULT_LOMS)
    cur.execute(SET_TAB_VERSION, (TAB_VERSION, ))
    db_iface.commit()
    cur.close()
示例#7
0
 def delete(self):
     #TODO : before delete the lom delete all the moms linked
     cur = db_iface.get_cursor()
     cur.execute(DELETE_LOM, (self.id, ))
     db_iface.commit()
     cur.close()
     self.name = None
     self.id = None
示例#8
0
文件: mom.py 项目: stethewwolf/Sapy
 def delete(self):
     cur = db_iface.get_cursor()
     cur.execute(DELETE_MOM, (self.id, ))
     cur.execute(DELETE_MOM_LINK, (self.id, ))
     db_iface.commit()
     cur.close()
     self.value = None
     self.cause = None
     self.time = None
     self.id = None
示例#9
0
    def add(self, mlist):
        cur = db_iface.get_cursor()
        for m in mlist:
            cur.execute(LINK_MOM_TO_LOM, (
                m.id,
                self.id,
            ))

        db_iface.commit()
        cur.close()
示例#10
0
    def database(self):
        # open db connection

        if not os.path.exists(self.cfg['private']['data']):
            db_iface.open()
            cur = db_iface.get_cursor()
            cur.execute(SapyValues.get_value('db.create.app_meta'))
            cur.execute(SapyValues.get_value('db.populate.app_meta'),
                        (SapyConstants.APP.VERSION, ))
            db_iface.commit()
            cur.close()
            moms.create_tables()
            loms.create_tables()
            tags.create_tables()
            objs.create_tables()
        else:
            db_iface.open()
示例#11
0
    def __init__(
        self,
        id=None,
        name='noname',
    ):
        self.name = name

        if id == None:
            cur = db_iface.get_cursor()
            cur.execute("insert into tags (name) values ( ? )", (name, ))

            cur.execute("select id from tags order by id DESC ;")
            self.id = cur.fetchone()[0]

            db_iface.commit()
            cur.close()
        else:
            self.id = id
示例#12
0
    def __init__(self,
                 id=None,
                 name="list of movements",
                 visible=False,
                 color="black"):
        self.logger = LoggerFactory.getLogger(str(self.__class__))
        self.name = name
        self.visible = visible
        self.color = color

        if id == None:
            cur = db_iface.get_cursor()
            cur.execute(INSERT_LOM, (name, visible, color))

            cur.execute(GET_LAST_LOM)
            self.id = cur.fetchone()[0]

            db_iface.commit()
            cur.close()
        else:
            self.id = id
示例#13
0
 def set_color(self, value):
     self.color = value
     cur = db_iface.get_cursor()
     cur.execute(UPDATE_LOM_COLOR, (self.color, self.id))
     db_iface.commit()
示例#14
0
 def set_name(self, value):
     self.name = value
     cur = db_iface.get_cursor()
     cur.execute(UPDATE_LOM_NAME, (self.name, self.id))
     db_iface.commit()