Example #1
0
    def delete(self):
        """
        Delete database entry for log item. Note that this does not destroy the
        Python object associated with the database entry, so once this method
        has been called, it is up to the caller to handle object discarding.
        """

        db.execute("""
            DELETE FROM log_{0} WHERE item_id=(?);
        """.format(self.log_id), (self.item_id))
Example #2
0
    def delete(self):
        """
        Delete database table for log. Note that this does not destroy the
        Python object associated with the database table, so once this method
        has been called, it is up to the caller to handle object discarding.
        """

        db.execute("""
            DROP TABLE log_{0};
        """.format(self.log_id))
Example #3
0
    def __init__(self, log_id: int):
        """
        Initialize the object.

        Todo:
            * Make log_id an optional argument, with an autoincrement default
            feature, starting at zero.
        """
        self._log_id = log_id # There should be no setter method for log_id.

        # Create log table in database if it does not exist.
        db.execute("""SELECT name FROM sqlite_master WHERE type='table';""")
        if "log_{0}".format(self.log_id) not in db.fetchall():
            db.execute("""
                CREATE TABLE log_{0} (
                    item_id INTEGER NOT NULL PRIMARY KEY,
                    parent_id INTEGER,
                    item_type TEXT,
                    datetime TEXT,
                    duration REAL
                );
            """.format(self.log_id))

        # Retrieve all log items from database table.
        db.execute("SELECT * FROM log_{0};".format(self.log_id))
        self.items = [LogItem(log_id, log_item) for log_item in db.fetchall()]
Example #4
0
 def parent_id(self, value):
     db.execute("""
         UPDATE log_{0} SET parent_id=(?) WHERE item_id=(?);
     """.format(self.log_id), (value, self.item_id))
     self._parent_id = value
Example #5
0
 def item_type(self, value):
     db.execute("""
         UPDATE log_{0} SET item_type=(?) WHERE item_id=(?);
     """.format(self.log_id), (value, self.item_id))
     self._item_type = value
Example #6
0
 def duration(self, value):
     db.execute("""
         UPDATE log_{0} SET duration=(?) WHERE item_id=(?);
     """.format(self.log_id), (value, self.item_id))
     self._duration = value
Example #7
0
 def datetime(self, value):
     db.execute("""
         UPDATE log_{0} SET datetime=(?) WHERE item_id=(?);
     """.format(self.log_id), (value, self.item_id))
     self._datetime = value