def articleRequest(self, group, index, id = None): if id is not None: sql = """ SELECT postings.article_index, articles.message_id, articles.header, articles.body FROM groups,postings LEFT OUTER JOIN articles ON articles.message_id = '%s' WHERE groups.name = '%s' AND groups.group_id = postings.group_id """ % (adbapi.safe(id), adbapi.safe(group)) else: sql = """ SELECT postings.article_index, articles.message_id, articles.header, articles.body FROM groups,articles LEFT OUTER JOIN postings ON postings.article_id = articles.article_id WHERE postings.article_index = %d AND postings.group_id = groups.group_id AND groups.name = '%s' """ % (index, adbapi._safe(group)) return self.dbpool.runQuery(sql).addCallback( lambda result: ( result[0][0], result[0][1], StringIO.StringIO(result[0][2] + '\r\n' + result[0][3]) ) )
def headRequest(self, group, index): sql = """ SELECT postings.article_index, articles.message_id, articles.header FROM groups,articles LEFT OUTER JOIN postings ON postings.article_id = articles.article_id WHERE postings.article_index = %d AND postings.group_id = groups.group_id AND groups.name = '%s' """ % (index, adbapi._safe(group)) return self.dbpool.runQuery(sql).addCallback(lambda result: result[0])
def xhdrRequest(self, group, low, high, header): sql = """ SELECT articles.header FROM groups,postings,articles WHERE groups.name = '%s' AND postings.group_id = groups.group_id AND postings.article_index >= %d AND postings.article_index <= %d """ % (adbapi._safe(group), low, high) return self.dbpool.runQuery(sql).addCallback(lambda results: [( i, Article(h, None).getHeader(h)) for (i, h) in results])
def xhdrRequest(self, group, low, high, header): sql = """ SELECT articles.header FROM groups,postings,articles WHERE groups.name = '%s' AND postings.group_id = groups.group_id AND postings.article_index >= %d AND postings.article_index <= %d """ % (adbapi._safe(group), low, high) return self.dbpool.runQuery(sql).addCallback( lambda results: [ (i, Article(h, None).getHeader(h)) for (i, h) in results ] )
def articleRequest(self, group, index, id=None): if id is not None: sql = """ SELECT postings.article_index, articles.message_id, articles.header, articles.body FROM groups,postings LEFT OUTER JOIN articles ON articles.message_id = '%s' WHERE groups.name = '%s' AND groups.group_id = postings.group_id """ % (adbapi.safe(id), adbapi.safe(group)) else: sql = """ SELECT postings.article_index, articles.message_id, articles.header, articles.body FROM groups,articles LEFT OUTER JOIN postings ON postings.article_id = articles.article_id WHERE postings.article_index = %d AND postings.group_id = groups.group_id AND groups.name = '%s' """ % (index, adbapi._safe(group)) return self.dbpool.runQuery(sql).addCallback( lambda result: (result[0][0], result[0][ 1], StringIO.StringIO(result[0][2] + '\r\n' + result[0][3])))
def safe(text): """ Make a string safe to include in an SQL statement. """ return _safe(text)