root/database/SourceHasFileDAO.py @ 96

Revision 96, 1.3 KB (checked in by vinicius, 5 years ago)

DAO class for jointable sourceHasfile implemented

Line 
1import sys
2import logging
3
4sys.path.append('./entities')
5from CommonDAO import CommonDAO
6
7class SourceHasFile(CommonDAO):
8
9    jointable = "source_has_file"
10
11    def __init__(self):
12        CommonDAO.__init__(self)
13   
14    def insertOrUpdate(self, sourceId, fileId, firstSeen):
15        rs = self.sourceHasFile(sourceId, fileId)
16        if not rs:
17            query = "INSERT INTO %s(source_id, file_id, firstSeen) VALUES(%d, %d, '%s')" % (self.jointable, sourceId, fileId, firstSeen)
18            logging.debug(query)
19            self.cursor.execute(query)
20        #CommonDAO.lastID(self, self.jointable)
21
22    def delete(self, sourceId, fileId):
23        self.cursor.execute("""DELETE FROM """+self.jointable+""" WHERE source_id = %s AND file_id = %s""", (sourceId, fileId))
24
25    def sourceHasFile(self, sourceId, fileId):
26        self.cursor.execute("""SELECT * FROM """+self.jointable+""" WHERE source_id = %s AND file_id = %s""", (sourceId, fileId))
27        rs = self.cursor.fetchall()
28        return rs
29
30    #def findByName(self, name):
31    #    self.cursor.execute("""SELECT * FROM """+self.tablename+""" WHERE name = %s""", (name,))
32    #    rs = self.cursor.fetchall()
33    #    if not rs:
34    #        return None
35    #    file = File()
36    #    for row in rs:
37    #        file.id = row[0]
38    #        file.name = row[1]
39    #    return file
Note: See TracBrowser for help on using the browser.