8 conn
= sqlite3
.connect(config
.DBPATH
)
9 conn
.execute("CREATE TABLE IF NOT EXISTS entries (id INTEGER PRIMARY KEY, date , title TEXT, text TEXT)")
10 except sqlite3
.OperationalError
:
11 print 'Failed to connect to database. Check file and directory permissions.'
15 def getnumposts(conn
, id=None):
16 """Enumerate the number of posts in the database. if an ID is specified
17 then enumerate the number of posts with that ID. The latter should be 0 or
18 1 so essentially this is a check for whether the specified post exists.
21 numposts
= conn
.execute("SELECT count(id) FROM entries WHERE id = ?", (id,)).fetchone()
23 numposts
= conn
.execute("SELECT count(id) FROM entries").fetchone()
24 return int(numposts
[0])