Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
# Provide stateful DB access accessible across functions
import sqlite3
class DB:
def __init__(self,dbpath):
self.db = sqlite3.connect(dbpath)
self.dbc = self.db.cursor()
def write(self,sqls):
# If sqls is a single string, convert to list of one
if not type(sqls) in ( type(()), type([]) ): sqls = [ sqls ]
for sql in sqls:
self.dbc.execute(sql)
self.db.commit()
def read(self,sql):
self.dbc.execute(sql)
return self.dbc.fetchall()
def close(self):
self.db.close()
# Only needed when creating the database
def create_tables(self):
CREATE_TABLE_SQLS = [
"""CREATE TABLE IF NOT EXISTS user_footprint (
datetime text,
userid integer,
user text,
rank integer,
count integer,
footprint integer,
primary key (datetime,user)
);
""",
"""CREATE TABLE IF NOT EXISTS homedir_footprint (
datetime text,
dir text,
rank integer,
count integer,
footprint integer,
primary key (datetime,dir)
);
""",
"""CREATE TABLE IF NOT EXISTS shareddir_footprint (
datetime text,
dir text,
rank integer,
count integer,
footprint integer,
primary key (datetime,dir)
);
"""
]
self.write(CREATE_TABLE_SQLS)