def getAssetDetails(self, pid, assetname): ''' Retrieves an asset matching assetname ''' # connect to database db = Database() db.open() # query to retrieve asset details assetname = common.getDbString( assetname ) query = "SELECT pid, assetname, assettype FROM projectassets WHERE pid=%s AND assetname='%s' " % (pid, assetname) # get rows returned by query rows = db.execSelectQuery( query ) # get asset details from record and assign to object attrbutes num = len(rows) if (num != 0): exists = True for row in rows: self.pid = pid self.name = common.getViewString( row[1] ) self.type = common.getViewString( row[2] ) else: exists = False # close database connection db.close() return exists
def getIncomeSourceDetails(self, pid, incomesourcename): ''' Retrieves a incomesource object corresponding to the given incomesourcename from database ''' # connect to database db = Database() db.open() # query to retrieve incomesource details incomesourcename = common.getDbString( incomesourcename ) query = "SELECT pid, incomesource, incometype FROM projectincomesources WHERE pid=%s AND incomesource='%s' " % (pid, incomesourcename) # get rows returned by query rows = db.execSelectQuery( query ) # get incomesource details from record and assign to object attrbutes num = len(rows) if (num != 0): exists = True for row in rows: self.pid = pid self.name = common.getViewString( row[1] ) self.type = common.getViewString( row[2] ) else: exists = False # close database connection db.close() return exists
def createAsset( self, pid, assetname, assettype ): ''' Adds a new incomesource object ''' # connect to database db = Database() db.open() # create INSERT INTO query assetname = common.getDbString( assetname ) assettype = common.getDbString( assettype ) query = '''INSERT INTO projectassets(pid,assetname,assettype) VALUES(%s,'%s','%s')''' % (pid,assetname,assettype) # execute query db.execUpdateQuery(query) # close database connection db.close() # set asset attributes to saved values self.name = common.getViewString( assetname ) self.type = common.getViewString( assettype ) self.pid = pid
def editData( self, assetname, assettype ): ''' edits the assetname and assettype of the asset object ''' # connect to database db = Database() db.open() # create INSERT INTO query assetname = common.getDbString( assetname ) oldname = common.getDbString( self.name ) assettype = common.getDbString( assettype ) query = '''UPDATE projectassets SET assetname='%s', assettype='%s', WHERE pid=%s AND assetname='%s' ''' % (assetname, assettype, self.pid, oldname) # execute query db.execUpdateQuery(query) # close database connection db.close() # set asset attributes to saved values self.name = common.getViewString( assetname ) self.type = common.getViewString( assettype )
def editIncomeSource( self, incomesourcename, incometype ): ''' edits the incomesourcename and category of the current incomesource object ''' # connect to database db = Database() db.open() # create INSERT INTO query incomesourcename = common.getDbString( incomesourcename ) oldname = common.getDbString( self.name ) incometype = common.getDbString( incometype ) query = '''UPDATE projectincomesources SET incomesource='%s', incometype='%s', WHERE pid=%s AND incomesourcename='%s' ''' % (incomesourcename, incometype, self.pid, oldname) # execute query db.execUpdateQuery(query) # close database connection db.close() # set incomesource attributes to saved values self.name = common.getViewString( incomesourcename ) self.type = common.getViewString( incometype )