]>
git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - pkgs/core/pakfire/src/python/db.py
3 from pysqlite2
import dbapi2
as sqlite
7 class Database(object):
8 def __init__(self
, filename
):
9 self
.filename
= filename
11 self
.connection
= sqlite
.connect(self
.filename
)
15 c
.executescript("CREATE TABLE IF NOT EXISTS %s(id, key, value);" % table
)
19 self
.connection
.commit()
21 def destroy(self
, table
):
23 c
.execute("DELETE FROM %s" % table
)
27 def get(self
, table
, id, key
):
30 c
.execute("SELECT value FROM %s WHERE id='%s' AND key='%s';" % \
39 def set(self
, table
, id, key
, value
):
41 if not self
.get(id, key
):
42 c
.execute("INSERT INTO %s(id, key, value) VALUES('%s', '%s', '%s');" \
43 % (table
, id, key
, value
,))
45 c
.execute("UPDATE %s SET value='%s' WHERE id='%s' AND key='%s';" \
46 % (table
, value
, id, key
,))
52 return self
.connection
.cursor()