# get the connection id of the Z SQL method "sql_insertMetadata" that inserts the meta-data
db_con = self.sql_insertMetadata.connection_id
# 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)
# create cursor
c = o.cursor()
# 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>
# 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())}
)
# commit on the database connection
o.commit()
|