Logo Search packages:      
Sourcecode: mbot version File versions  Download package

def PgNewsHandler::PgNewsHandler::add_img (   self,
  filename,
  filetype,
  filedata,
  TNfiledata,
  filesize 
)

Add an image as a Large Object in the database 

Definition at line 56 of file PgNewsHandler.py.

00056                                                                          :
        """ Add an image as a Large Object in the database """ 

        self.log.notice("[PgNewsHandler]: add_img")

        news_id   = self.id
        desc      = "[News] " + filename
        
        db      = self.dbconn()
        db.query("begin")

        # We create Large Object
        img_LO   = db.locreate(INV_WRITE)
        TNimg_LO = db.locreate(INV_WRITE)

        img_LO.open(INV_WRITE)
        img_LO.write(filedata)
        img_LO.close()
        
        TNimg_LO.open(INV_WRITE)
        TNimg_LO.write(TNfiledata)
        TNimg_LO.close()
        
        # The SQL query
        sql = """
        INSERT INTO %s (description, img_data, tnimg_data,
                        filename, filesize,filetype)
        VALUES ('%s','%s','%s','%s','%d','%s')
        """ % (self.photo_tbl, desc, img_LO.oid, TNimg_LO.oid,
               filename, filesize, filetype)
        req      = db.query(sql)

        db.query("commit")

        # Now we add the link to the image from the news table
        id      = self.getid(db, self.photo_tblsq)
        self.log.debug("[PgNewsHandler]: add_img => id='%d'" % id)
        myquery   = "UPDATE %s SET id_img='%d' WHERE id='%d'" \
                  % (self.news_tbl, id, news_id)
        
        req     = db.query(myquery)
        db.close()

        return id
      
      


Generated by  Doxygen 1.6.0   Back to index