Module notesql

Expand source code
# -------------------------------------------------------------------
# Dead code; Saved for possible cut paste


class notesql():

    def __init__(self, file):

        #self.take = 0
        self.errstr = ""
        try:
            self.conn = sqlite3.connect(file)
        except:
            print("Cannot open/create db:", file, sys.exc_info())
            pedconfig.conf.pedwin.update_statusbar("Cannot open/create the database.");
            return
        try:
            self.c = self.conn.cursor()
            # Create table
            self.c.execute("create table if not exists notes \
             (pri INTEGER PRIMARY KEY, key text, val text, val2 text, val3 text)")
            self.c.execute("create index if not exists knotes on notes (key)")
            self.c.execute("create index if not exists pnotes on notes (pri)")
            self.c.execute("create table if not exists notedata \
             (pri INTEGER PRIMARY KEY, key text, val text, val2 text, val3 text)")
            self.c.execute("create index if not exists knotedata on notedata (key)")
            self.c.execute("create index if not exists pnotedata on notedata (pri)")

            self.c.execute("PRAGMA synchronous=OFF")
            # Save (commit) the changes
            self.conn.commit()
        except:
            print("Cannot insert sql data", sys.exc_info())
            self.errstr = "Cannot insert sql data" + str(sys.exc_info())

        try:
            self.c.execute("create table if not exists logs \
             (pri INTEGER PRIMARY KEY, key text, val text, val2 text, val3 text)")
            self.c.execute("create index if not exists klog on logs (key)")
            self.c.execute("create index if not exists plog on logs (pri)")
            self.c.execute("create table if not exists logdata \
             (pri INTEGER PRIMARY KEY, key text, val text, val2 text, val3 text)")
            self.c.execute("create index if not exists klogdata on logdata (key)")
            self.c.execute("create index if not exists plogdata on logdata (pri)")
        except:
            print("Cannot create log table ", sys.exc_info())
            self.errstr = "Cannot create log table " + str(sys.exc_info())

        finally:
            # We close the cursor, we are done with it
            #c.close()
            pass

    # --------------------------------------------------------------------
    # Return None if no data

    def   get(self, kkk):
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notes where key = ?", (kkk,))
            else:
                self.c.execute("select * from notes indexed by knotes where key = ?", (kkk,))
            rr = self.c.fetchone()
        except:
            print("Cannot get sql data", sys.exc_info())
            rr = None
            self.errstr = "Cannot get sql data" + str(sys.exc_info())

        finally:
            #c.close
            pass
        return rr

    def   gethead(self, vvv):
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notes where val = ?", (vvv,))
            else:
                self.c.execute("select * from notes indexed by knotes where val = ?", (vvv,))
            rr = self.c.fetchone()
        except:
            print("Cannot get sql data", sys.exc_info())
            rr = None
            self.errstr = "Cannot get sql data" + str(sys.exc_info())

        finally:
            #c.close
            pass

        return rr

    def   findhead(self, vvv):
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notes where val like ?", (vvv,))
            else:
                self.c.execute("select * from notes indexed by knotes where val like ?", (vvv,))
            rr = self.c.fetchall()
        except:
            print("Cannot get sql data", sys.exc_info())
            rr = None
            self.errstr = "Cannot get sql data" + str(sys.exc_info())

        finally:
            #c.close
            pass
        return rr

    def   getdata(self, kkk):
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notedata where key = ?", (kkk,))
            else:
                self.c.execute("select * from notedata indexed by knotedata where key = ?", (kkk,))
            rr = self.c.fetchone()
        except:
            print("Cannot get sql data", sys.exc_info())
            rr = None
            self.errstr = "Cannot get sql data" + str(sys.exc_info())

        finally:
            #c.close
            pass
        if rr:
            return (rr[2], rr[3], rr[4])
        else:
            return ("",)

    # --------------------------------------------------------------------
    # Return False if cannot put data

    def   put(self, key, val, val2, val3):

        #got_clock = time.clock()

        ret = True
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notes where key = ?", (key,))
            else:
                self.c.execute("select * from notes indexed by knotes where key = ?", (key,))
            rr = self.c.fetchall()
            if rr == []:
                #print "inserting"
                self.c.execute("insert into notes (key, val, val2, val3) \
                    values (?, ?, ?, ?)", (key, val, val2, val3))
            else:
                #print "updating"
                if os.name == "nt":
                    self.c.execute("update notes \
                                set val = ? val2 = ?, val3 = ? where key = ?", \
                                      (val, val2, val3, key))
                else:
                    self.c.execute("update notes indexed by knotes \
                                set val = ?, val2 = ?, val3 = ? where key = ?",\
                                     (val, val2, val3, key))
            self.conn.commit()
        except:
            print("Cannot put sql data", sys.exc_info())
            self.errstr = "Cannot put sql data" + str(sys.exc_info())
            ret = False
        finally:
            #c.close
            pass

        #self.take += time.clock() - got_clock

        return ret

    # --------------------------------------------------------------------
    # Return False if cannot put data

    def   putdata(self, key, val, val2, val3):

        #got_clock = time.clock()

        ret = True
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notedata where key == ?", (key,))
            else:
                self.c.execute("select * from notedata indexed by knotedata where key = ?", (key,))
            rr = self.c.fetchall()
            if rr == []:
                #print "inserting"
                self.c.execute("insert into notedata (key, val, val2, val3) \
                    values (?, ?, ?, ?)", (key, val, val2, val3))
            else:
                #print "updating"
                if os.name == "nt":
                    self.c.execute("update notedata \
                                set val = ? val2 = ?, val3 = ? where key = ?", \
                                      (val, val2, val3, key))
                else:
                    self.c.execute("update notedata indexed by knotedata \
                                set val = ?, val2 = ?, val3 = ? where key = ?",\
                                     (val, val2, val3, key))
            self.conn.commit()
        except:
            print("Cannot put sql data", sys.exc_info())
            self.errstr = "Cannot put sql data" + str(sys.exc_info())
            ret = False
        finally:
            #c.close
            pass

        #self.take += time.clock() - got_clock

        return ret

    # --------------------------------------------------------------------
    # Return False if cannot put data

    def   putlog(self, key, val, val2, val3):

        #got_clock = time.clock()

        ret = True
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from logdata where key == ?", (key,))
            else:
                self.c.execute("select * from logdata indexed by klogdata where key = ?", (key,))
            rr = self.c.fetchall()
            if rr == []:
                #print "inserting"
                self.c.execute("insert into logdata (key, val, val2, val3) \
                    values (?, ?, ?, ?)", (key, val, val2, val3))
            else:
                #print "updating"
                if os.name == "nt":
                    self.c.execute("update logdata \
                                set val = ? val2 = ?, val3 = ? where key = ?", \
                                      (val, val2, val3, key))
                else:
                    self.c.execute("update logdata indexed by klogdata \
                                set val = ?, val2 = ?, val3 = ? where key = ?",\
                                     (val, val2, val3, key))
            self.conn.commit()
        except:
            print("Cannot put sql log data", sys.exc_info())
            self.errstr = "Cannot put sql log data" + str(sys.exc_info())
            ret = False
        finally:
            #c.close
            pass

        #self.take += time.clock() - got_clock

        return ret

    # --------------------------------------------------------------------
    # Get All

    def   getall(self):

        try:
            #c = self.conn.cursor()
            self.c.execute("select * from notes")
            rr = self.c.fetchall()
        except:
            rr = []
            print("Cannot get all sql data", sys.exc_info())
            self.errstr = "Cannot get sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        return rr

    def   getalldata(self):
        try:
            #c = self.conn.cursor()
            self.c.execute("select * from notedata")
            rr = self.c.fetchall()
        except:
            rr = []
            print("Cannot get all sql data", sys.exc_info())
            self.errstr = "Cannot get sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        return rr

    def   rmone(self, key):
        #print("removing one '%s'" % key)
        try:
            #c = self.conn.cursor()
            self.c.execute("delete from notes where key = ?", (key,))
            self.conn.commit()
            rr = self.c.fetchone()
        except:
            rr = []
            print("Cannot delete sql data", sys.exc_info())
            self.errstr = "Cannot delete sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        return rr

    def   rmonedata(self, key):
        #print("removing one data '%s'" % key)
        try:
            #c = self.conn.cursor()
            self.c.execute("delete from notedata where key = ?", (key,))
            self.conn.commit()
            rr = self.c.fetchone()
        except:
            rr = []
            print("Cannot delete sql data", sys.exc_info())
            self.errstr = "Cannot delete sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        return rr

# --------------------------------------------------------------------
    # Return None if no data

    def   rmall(self):
        print("removing all")
        try:
            #c = self.conn.cursor()
            self.c.execute("delete from notes")
            rr = self.c.fetchone()
        except:
            print("Cannot delete sql data", sys.exc_info())
            self.errstr = "Cannot delete sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        if rr:
            return rr[1]
        else:
            return None

    def   rmalldata(self):
        print("removing all")
        try:
            #c = self.conn.cursor()
            self.c.execute("delete from notedata")
            rr = self.c.fetchone()
        except:
            print("Cannot delete sql data", sys.exc_info())
            self.errstr = "Cannot get sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        if rr:
            return rr[1]
        else:
            return None

Classes

class notesql (file)
Expand source code
class notesql():

    def __init__(self, file):

        #self.take = 0
        self.errstr = ""
        try:
            self.conn = sqlite3.connect(file)
        except:
            print("Cannot open/create db:", file, sys.exc_info())
            pedconfig.conf.pedwin.update_statusbar("Cannot open/create the database.");
            return
        try:
            self.c = self.conn.cursor()
            # Create table
            self.c.execute("create table if not exists notes \
             (pri INTEGER PRIMARY KEY, key text, val text, val2 text, val3 text)")
            self.c.execute("create index if not exists knotes on notes (key)")
            self.c.execute("create index if not exists pnotes on notes (pri)")
            self.c.execute("create table if not exists notedata \
             (pri INTEGER PRIMARY KEY, key text, val text, val2 text, val3 text)")
            self.c.execute("create index if not exists knotedata on notedata (key)")
            self.c.execute("create index if not exists pnotedata on notedata (pri)")

            self.c.execute("PRAGMA synchronous=OFF")
            # Save (commit) the changes
            self.conn.commit()
        except:
            print("Cannot insert sql data", sys.exc_info())
            self.errstr = "Cannot insert sql data" + str(sys.exc_info())

        try:
            self.c.execute("create table if not exists logs \
             (pri INTEGER PRIMARY KEY, key text, val text, val2 text, val3 text)")
            self.c.execute("create index if not exists klog on logs (key)")
            self.c.execute("create index if not exists plog on logs (pri)")
            self.c.execute("create table if not exists logdata \
             (pri INTEGER PRIMARY KEY, key text, val text, val2 text, val3 text)")
            self.c.execute("create index if not exists klogdata on logdata (key)")
            self.c.execute("create index if not exists plogdata on logdata (pri)")
        except:
            print("Cannot create log table ", sys.exc_info())
            self.errstr = "Cannot create log table " + str(sys.exc_info())

        finally:
            # We close the cursor, we are done with it
            #c.close()
            pass

    # --------------------------------------------------------------------
    # Return None if no data

    def   get(self, kkk):
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notes where key = ?", (kkk,))
            else:
                self.c.execute("select * from notes indexed by knotes where key = ?", (kkk,))
            rr = self.c.fetchone()
        except:
            print("Cannot get sql data", sys.exc_info())
            rr = None
            self.errstr = "Cannot get sql data" + str(sys.exc_info())

        finally:
            #c.close
            pass
        return rr

    def   gethead(self, vvv):
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notes where val = ?", (vvv,))
            else:
                self.c.execute("select * from notes indexed by knotes where val = ?", (vvv,))
            rr = self.c.fetchone()
        except:
            print("Cannot get sql data", sys.exc_info())
            rr = None
            self.errstr = "Cannot get sql data" + str(sys.exc_info())

        finally:
            #c.close
            pass

        return rr

    def   findhead(self, vvv):
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notes where val like ?", (vvv,))
            else:
                self.c.execute("select * from notes indexed by knotes where val like ?", (vvv,))
            rr = self.c.fetchall()
        except:
            print("Cannot get sql data", sys.exc_info())
            rr = None
            self.errstr = "Cannot get sql data" + str(sys.exc_info())

        finally:
            #c.close
            pass
        return rr

    def   getdata(self, kkk):
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notedata where key = ?", (kkk,))
            else:
                self.c.execute("select * from notedata indexed by knotedata where key = ?", (kkk,))
            rr = self.c.fetchone()
        except:
            print("Cannot get sql data", sys.exc_info())
            rr = None
            self.errstr = "Cannot get sql data" + str(sys.exc_info())

        finally:
            #c.close
            pass
        if rr:
            return (rr[2], rr[3], rr[4])
        else:
            return ("",)

    # --------------------------------------------------------------------
    # Return False if cannot put data

    def   put(self, key, val, val2, val3):

        #got_clock = time.clock()

        ret = True
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notes where key = ?", (key,))
            else:
                self.c.execute("select * from notes indexed by knotes where key = ?", (key,))
            rr = self.c.fetchall()
            if rr == []:
                #print "inserting"
                self.c.execute("insert into notes (key, val, val2, val3) \
                    values (?, ?, ?, ?)", (key, val, val2, val3))
            else:
                #print "updating"
                if os.name == "nt":
                    self.c.execute("update notes \
                                set val = ? val2 = ?, val3 = ? where key = ?", \
                                      (val, val2, val3, key))
                else:
                    self.c.execute("update notes indexed by knotes \
                                set val = ?, val2 = ?, val3 = ? where key = ?",\
                                     (val, val2, val3, key))
            self.conn.commit()
        except:
            print("Cannot put sql data", sys.exc_info())
            self.errstr = "Cannot put sql data" + str(sys.exc_info())
            ret = False
        finally:
            #c.close
            pass

        #self.take += time.clock() - got_clock

        return ret

    # --------------------------------------------------------------------
    # Return False if cannot put data

    def   putdata(self, key, val, val2, val3):

        #got_clock = time.clock()

        ret = True
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from notedata where key == ?", (key,))
            else:
                self.c.execute("select * from notedata indexed by knotedata where key = ?", (key,))
            rr = self.c.fetchall()
            if rr == []:
                #print "inserting"
                self.c.execute("insert into notedata (key, val, val2, val3) \
                    values (?, ?, ?, ?)", (key, val, val2, val3))
            else:
                #print "updating"
                if os.name == "nt":
                    self.c.execute("update notedata \
                                set val = ? val2 = ?, val3 = ? where key = ?", \
                                      (val, val2, val3, key))
                else:
                    self.c.execute("update notedata indexed by knotedata \
                                set val = ?, val2 = ?, val3 = ? where key = ?",\
                                     (val, val2, val3, key))
            self.conn.commit()
        except:
            print("Cannot put sql data", sys.exc_info())
            self.errstr = "Cannot put sql data" + str(sys.exc_info())
            ret = False
        finally:
            #c.close
            pass

        #self.take += time.clock() - got_clock

        return ret

    # --------------------------------------------------------------------
    # Return False if cannot put data

    def   putlog(self, key, val, val2, val3):

        #got_clock = time.clock()

        ret = True
        try:
            #c = self.conn.cursor()
            if os.name == "nt":
                self.c.execute("select * from logdata where key == ?", (key,))
            else:
                self.c.execute("select * from logdata indexed by klogdata where key = ?", (key,))
            rr = self.c.fetchall()
            if rr == []:
                #print "inserting"
                self.c.execute("insert into logdata (key, val, val2, val3) \
                    values (?, ?, ?, ?)", (key, val, val2, val3))
            else:
                #print "updating"
                if os.name == "nt":
                    self.c.execute("update logdata \
                                set val = ? val2 = ?, val3 = ? where key = ?", \
                                      (val, val2, val3, key))
                else:
                    self.c.execute("update logdata indexed by klogdata \
                                set val = ?, val2 = ?, val3 = ? where key = ?",\
                                     (val, val2, val3, key))
            self.conn.commit()
        except:
            print("Cannot put sql log data", sys.exc_info())
            self.errstr = "Cannot put sql log data" + str(sys.exc_info())
            ret = False
        finally:
            #c.close
            pass

        #self.take += time.clock() - got_clock

        return ret

    # --------------------------------------------------------------------
    # Get All

    def   getall(self):

        try:
            #c = self.conn.cursor()
            self.c.execute("select * from notes")
            rr = self.c.fetchall()
        except:
            rr = []
            print("Cannot get all sql data", sys.exc_info())
            self.errstr = "Cannot get sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        return rr

    def   getalldata(self):
        try:
            #c = self.conn.cursor()
            self.c.execute("select * from notedata")
            rr = self.c.fetchall()
        except:
            rr = []
            print("Cannot get all sql data", sys.exc_info())
            self.errstr = "Cannot get sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        return rr

    def   rmone(self, key):
        #print("removing one '%s'" % key)
        try:
            #c = self.conn.cursor()
            self.c.execute("delete from notes where key = ?", (key,))
            self.conn.commit()
            rr = self.c.fetchone()
        except:
            rr = []
            print("Cannot delete sql data", sys.exc_info())
            self.errstr = "Cannot delete sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        return rr

    def   rmonedata(self, key):
        #print("removing one data '%s'" % key)
        try:
            #c = self.conn.cursor()
            self.c.execute("delete from notedata where key = ?", (key,))
            self.conn.commit()
            rr = self.c.fetchone()
        except:
            rr = []
            print("Cannot delete sql data", sys.exc_info())
            self.errstr = "Cannot delete sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        return rr

# --------------------------------------------------------------------
    # Return None if no data

    def   rmall(self):
        print("removing all")
        try:
            #c = self.conn.cursor()
            self.c.execute("delete from notes")
            rr = self.c.fetchone()
        except:
            print("Cannot delete sql data", sys.exc_info())
            self.errstr = "Cannot delete sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        if rr:
            return rr[1]
        else:
            return None

    def   rmalldata(self):
        print("removing all")
        try:
            #c = self.conn.cursor()
            self.c.execute("delete from notedata")
            rr = self.c.fetchone()
        except:
            print("Cannot delete sql data", sys.exc_info())
            self.errstr = "Cannot get sql data" + str(sys.exc_info())
        finally:
            #c.close
            pass
        if rr:
            return rr[1]
        else:
            return None

Methods

def findhead(self, vvv)
Expand source code
def   findhead(self, vvv):
    try:
        #c = self.conn.cursor()
        if os.name == "nt":
            self.c.execute("select * from notes where val like ?", (vvv,))
        else:
            self.c.execute("select * from notes indexed by knotes where val like ?", (vvv,))
        rr = self.c.fetchall()
    except:
        print("Cannot get sql data", sys.exc_info())
        rr = None
        self.errstr = "Cannot get sql data" + str(sys.exc_info())

    finally:
        #c.close
        pass
    return rr
def get(self, kkk)
Expand source code
def   get(self, kkk):
    try:
        #c = self.conn.cursor()
        if os.name == "nt":
            self.c.execute("select * from notes where key = ?", (kkk,))
        else:
            self.c.execute("select * from notes indexed by knotes where key = ?", (kkk,))
        rr = self.c.fetchone()
    except:
        print("Cannot get sql data", sys.exc_info())
        rr = None
        self.errstr = "Cannot get sql data" + str(sys.exc_info())

    finally:
        #c.close
        pass
    return rr
def getall(self)
Expand source code
def   getall(self):

    try:
        #c = self.conn.cursor()
        self.c.execute("select * from notes")
        rr = self.c.fetchall()
    except:
        rr = []
        print("Cannot get all sql data", sys.exc_info())
        self.errstr = "Cannot get sql data" + str(sys.exc_info())
    finally:
        #c.close
        pass
    return rr
def getalldata(self)
Expand source code
def   getalldata(self):
    try:
        #c = self.conn.cursor()
        self.c.execute("select * from notedata")
        rr = self.c.fetchall()
    except:
        rr = []
        print("Cannot get all sql data", sys.exc_info())
        self.errstr = "Cannot get sql data" + str(sys.exc_info())
    finally:
        #c.close
        pass
    return rr
def getdata(self, kkk)
Expand source code
def   getdata(self, kkk):
    try:
        #c = self.conn.cursor()
        if os.name == "nt":
            self.c.execute("select * from notedata where key = ?", (kkk,))
        else:
            self.c.execute("select * from notedata indexed by knotedata where key = ?", (kkk,))
        rr = self.c.fetchone()
    except:
        print("Cannot get sql data", sys.exc_info())
        rr = None
        self.errstr = "Cannot get sql data" + str(sys.exc_info())

    finally:
        #c.close
        pass
    if rr:
        return (rr[2], rr[3], rr[4])
    else:
        return ("",)
def gethead(self, vvv)
Expand source code
def   gethead(self, vvv):
    try:
        #c = self.conn.cursor()
        if os.name == "nt":
            self.c.execute("select * from notes where val = ?", (vvv,))
        else:
            self.c.execute("select * from notes indexed by knotes where val = ?", (vvv,))
        rr = self.c.fetchone()
    except:
        print("Cannot get sql data", sys.exc_info())
        rr = None
        self.errstr = "Cannot get sql data" + str(sys.exc_info())

    finally:
        #c.close
        pass

    return rr
def put(self, key, val, val2, val3)
Expand source code
def   put(self, key, val, val2, val3):

    #got_clock = time.clock()

    ret = True
    try:
        #c = self.conn.cursor()
        if os.name == "nt":
            self.c.execute("select * from notes where key = ?", (key,))
        else:
            self.c.execute("select * from notes indexed by knotes where key = ?", (key,))
        rr = self.c.fetchall()
        if rr == []:
            #print "inserting"
            self.c.execute("insert into notes (key, val, val2, val3) \
                values (?, ?, ?, ?)", (key, val, val2, val3))
        else:
            #print "updating"
            if os.name == "nt":
                self.c.execute("update notes \
                            set val = ? val2 = ?, val3 = ? where key = ?", \
                                  (val, val2, val3, key))
            else:
                self.c.execute("update notes indexed by knotes \
                            set val = ?, val2 = ?, val3 = ? where key = ?",\
                                 (val, val2, val3, key))
        self.conn.commit()
    except:
        print("Cannot put sql data", sys.exc_info())
        self.errstr = "Cannot put sql data" + str(sys.exc_info())
        ret = False
    finally:
        #c.close
        pass

    #self.take += time.clock() - got_clock

    return ret
def putdata(self, key, val, val2, val3)
Expand source code
def   putdata(self, key, val, val2, val3):

    #got_clock = time.clock()

    ret = True
    try:
        #c = self.conn.cursor()
        if os.name == "nt":
            self.c.execute("select * from notedata where key == ?", (key,))
        else:
            self.c.execute("select * from notedata indexed by knotedata where key = ?", (key,))
        rr = self.c.fetchall()
        if rr == []:
            #print "inserting"
            self.c.execute("insert into notedata (key, val, val2, val3) \
                values (?, ?, ?, ?)", (key, val, val2, val3))
        else:
            #print "updating"
            if os.name == "nt":
                self.c.execute("update notedata \
                            set val = ? val2 = ?, val3 = ? where key = ?", \
                                  (val, val2, val3, key))
            else:
                self.c.execute("update notedata indexed by knotedata \
                            set val = ?, val2 = ?, val3 = ? where key = ?",\
                                 (val, val2, val3, key))
        self.conn.commit()
    except:
        print("Cannot put sql data", sys.exc_info())
        self.errstr = "Cannot put sql data" + str(sys.exc_info())
        ret = False
    finally:
        #c.close
        pass

    #self.take += time.clock() - got_clock

    return ret
def putlog(self, key, val, val2, val3)
Expand source code
def   putlog(self, key, val, val2, val3):

    #got_clock = time.clock()

    ret = True
    try:
        #c = self.conn.cursor()
        if os.name == "nt":
            self.c.execute("select * from logdata where key == ?", (key,))
        else:
            self.c.execute("select * from logdata indexed by klogdata where key = ?", (key,))
        rr = self.c.fetchall()
        if rr == []:
            #print "inserting"
            self.c.execute("insert into logdata (key, val, val2, val3) \
                values (?, ?, ?, ?)", (key, val, val2, val3))
        else:
            #print "updating"
            if os.name == "nt":
                self.c.execute("update logdata \
                            set val = ? val2 = ?, val3 = ? where key = ?", \
                                  (val, val2, val3, key))
            else:
                self.c.execute("update logdata indexed by klogdata \
                            set val = ?, val2 = ?, val3 = ? where key = ?",\
                                 (val, val2, val3, key))
        self.conn.commit()
    except:
        print("Cannot put sql log data", sys.exc_info())
        self.errstr = "Cannot put sql log data" + str(sys.exc_info())
        ret = False
    finally:
        #c.close
        pass

    #self.take += time.clock() - got_clock

    return ret
def rmall(self)
Expand source code
def   rmall(self):
    print("removing all")
    try:
        #c = self.conn.cursor()
        self.c.execute("delete from notes")
        rr = self.c.fetchone()
    except:
        print("Cannot delete sql data", sys.exc_info())
        self.errstr = "Cannot delete sql data" + str(sys.exc_info())
    finally:
        #c.close
        pass
    if rr:
        return rr[1]
    else:
        return None
def rmalldata(self)
Expand source code
def   rmalldata(self):
    print("removing all")
    try:
        #c = self.conn.cursor()
        self.c.execute("delete from notedata")
        rr = self.c.fetchone()
    except:
        print("Cannot delete sql data", sys.exc_info())
        self.errstr = "Cannot get sql data" + str(sys.exc_info())
    finally:
        #c.close
        pass
    if rr:
        return rr[1]
    else:
        return None
def rmone(self, key)
Expand source code
def   rmone(self, key):
    #print("removing one '%s'" % key)
    try:
        #c = self.conn.cursor()
        self.c.execute("delete from notes where key = ?", (key,))
        self.conn.commit()
        rr = self.c.fetchone()
    except:
        rr = []
        print("Cannot delete sql data", sys.exc_info())
        self.errstr = "Cannot delete sql data" + str(sys.exc_info())
    finally:
        #c.close
        pass
    return rr
def rmonedata(self, key)
Expand source code
def   rmonedata(self, key):
    #print("removing one data '%s'" % key)
    try:
        #c = self.conn.cursor()
        self.c.execute("delete from notedata where key = ?", (key,))
        self.conn.commit()
        rr = self.c.fetchone()
    except:
        rr = []
        print("Cannot delete sql data", sys.exc_info())
        self.errstr = "Cannot delete sql data" + str(sys.exc_info())
    finally:
        #c.close
        pass
    return rr