+# Function to get articles from a category or all articles (inner join with categories to get category stub)
+def site_articles (dbname, catid = None):
+ try:
+ conn = sqlite3.connect (dbname)
+ c = conn.cursor ()
+ if catid is None:
+ c.execute ("SELECT * FROM articles INNER JOIN categories ON articles.cid=categories.cid \
+ ORDER BY cdate DESC;")
+ else:
+ c.execute ("SELECT * FROM articles INNER JOIN categories ON articles.cid=categories.cid \
+ WHERE articles.cid=? ORDER BY cdate DESC;", (catid,))
+ conn.commit ()
+ rows = c.fetchall ()
+ conn.close ()
+ return rows
+ except sqlite3.Error:
+ return False
+