ZopeMag's mascot the ZOPE fish

  1. # get the connection id of the Z SQL method "sql_insertMetadata" that inserts the meta-data
    db_con = self.sql_insertMetadata.connection_id
  2. # get the database connection object that is used by the Z SQL method "sql_insertMetadata"
    dba = self.aq_acquire(db_con)
    

    # open a database connection and pass the connection string of the 'dba' object o = psycopg.connect(dba.connection_string)
  3. # create cursor

    c = o.cursor()
  4. # check if the filename already exists or if no filename was entered
    # check which table the binary data is supposed to go into (either "tbl_ productinfo" or "tbl_download");

    if (tbl_name=='tbl_download' and len(self.sql_checkDownload(file_name=title))!=0) or (title == ''):
    if tbl_name=='tbl_download' and len(self.sql_checkDownload(file_name=title))!=0:
    REQUEST.RESPONSE.redirect('addDocumentMethod?msg=This+file+already+exists.')
    elif title == '':
    REQUEST.RESPONSE.redirect('addDocumentMethod?msg=lease+type+in+a+filename.')
    else:


    if tbl_name=='tbl_productinfo':
    …<execute query>


    elif tbl_name=='tbl_download':
    lt;execute query>
  5. # execute the query; inserting data into "tbl_productinfo"
                	c.execute("INSERT INTO tbl_productinfo (obj_id, imagename, imagedata) 
                                    VALUES (%(obj_id)i, %(img_title)s, %(data)s)",
                                    {'obj_id':obj_id, 'img_title':title, 'data':psycopg.Binary(file.read())}
                     	  )
  6. # commit on the database connection
            	o.commit()



Home   Subscribe   FAQ   Contact   Write for us   Privacy Policy   Weekly News   PyZine   opensourcexperts.com  

Reproduction of material from any of ZopeMag's pages without prior written permission is strictly prohibited. Copyright 2003 - 2005 ZopeMag Zope/Plone hosting by Nidelven IT