Commit 9c17dead authored by Florian Pritz's avatar Florian Pritz
Browse files

Add primary key to table



Oops. There should have been an index there... Having it should improve
performance somewhat.
Signed-off-by: Florian Pritz's avatarFlorian Pritz <bluewind@xinu.at>
parent a6c599ff
......@@ -7,9 +7,28 @@ class DB:
def init_db(self):
c = self.db.cursor()
c.execute('create table if not exists files (filename text, uploaded int)')
version = self._get_version()
if version is None:
c.execute('create table if not exists files (filename text, uploaded int)')
self._set_version(1)
version = 1
if version < 2:
c.execute('alter table files rename to files_old;')
c.execute('create table files (filename text, uploaded int, primary key (`filename`)) without rowid;')
c.execute('insert into files select * from files_old;')
c.execute('drop table files_old;')
self._set_version(2)
self.db.commit()
def _get_version(self):
self.db.cursor().execute('pragma user_version').fetchone()[0]
def _set_version(self, version):
self.db.cursor().execute('pragma user_version='+str(version))
def add_file(self, filename):
c = self.db.cursor()
c.execute('insert into files (filename, uploaded) values (?, 1)',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment